fix: search/replace bad case (#1223)

This commit is contained in:
yetone 2025-02-09 01:39:00 +08:00 committed by GitHub
parent e70b0fa243
commit 4ffec5a039
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -225,11 +225,17 @@ local function transform_result_content(selected_files, result_content, prev_fil
if next_line and next_line:match("^%s*```%w+$") then i = i + 1 end if next_line and next_line:match("^%s*```%w+$") then i = i + 1 end
search_start = i + 1 search_start = i + 1
last_search_tag_start_line = i last_search_tag_start_line = i
elseif line_content == "</SEARCH>" then elseif line_content:match("</SEARCH>") then
is_searching = false is_searching = false
local search_end = i local search_end = i
-- Handle case where </SEARCH> is a suffix
if not line_content:match("^%s*</SEARCH>%s*$") then
local search_end_line = line_content:match("^(.+)</SEARCH>")
result_lines[i] = search_end_line
end
local prev_line = result_lines[i - 1] local prev_line = result_lines[i - 1]
if prev_line and prev_line:match("^%s*```$") then search_end = i - 1 end if prev_line and prev_line:match("^%s*```$") then search_end = i - 1 end
@ -317,8 +323,13 @@ local function transform_result_content(selected_files, result_content, prev_fil
if next_line and next_line:match("^%s*```%w+$") then i = i + 1 end if next_line and next_line:match("^%s*```%w+$") then i = i + 1 end
last_replace_tag_start_line = i last_replace_tag_start_line = i
goto continue goto continue
elseif line_content == "</REPLACE>" then elseif line_content:match("</REPLACE>") then
is_replacing = false is_replacing = false
-- Handle case where </REPLACE> is a suffix
if not line_content:match("^%s*</REPLACE>%s*$") then
local replace_end_line = line_content:match("^(.+)</REPLACE>")
if replace_end_line and replace_end_line ~= "" then table.insert(transformed_lines, replace_end_line) end
end
local prev_line = result_lines[i - 1] local prev_line = result_lines[i - 1]
if not (prev_line and prev_line:match("^%s*```$")) then table.insert(transformed_lines, "```") end if not (prev_line and prev_line:match("^%s*```$")) then table.insert(transformed_lines, "```") end
goto continue goto continue