From 4ffec5a03948a8eb6de41f0b513d61e747c5a136 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 9 Feb 2025 01:39:00 +0800 Subject: [PATCH] fix: search/replace bad case (#1223) --- lua/avante/sidebar.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index c8c5a3c..c372a9f 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -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 search_start = i + 1 last_search_tag_start_line = i - elseif line_content == "" then + elseif line_content:match("") then is_searching = false local search_end = i + -- Handle case where is a suffix + if not line_content:match("^%s*%s*$") then + local search_end_line = line_content:match("^(.+)") + result_lines[i] = search_end_line + end + local prev_line = result_lines[i - 1] 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 last_replace_tag_start_line = i goto continue - elseif line_content == "" then + elseif line_content:match("") then is_replacing = false + -- Handle case where is a suffix + if not line_content:match("^%s*%s*$") then + local replace_end_line = line_content:match("^(.+)") + 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] if not (prev_line and prev_line:match("^%s*```$")) then table.insert(transformed_lines, "```") end goto continue