From b677505b8df791150dd0529fcd7cf19382ff1184 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 16 Jan 2025 21:38:40 +0800 Subject: [PATCH] fix: suggetion in the middle of line --- lua/avante/suggestion.lua | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lua/avante/suggestion.lua b/lua/avante/suggestion.lua index fc68a5b46..b9efd3934 100644 --- a/lua/avante/suggestion.lua +++ b/lua/avante/suggestion.lua @@ -206,6 +206,8 @@ L5: pass end function Suggestion:show() + Utils.debug("showing suggestions, mode:", fn.mode()) + self:hide() if not fn.mode():match("^[iR]") then return end @@ -231,14 +233,23 @@ function Suggestion:show() local virt_text_win_col = 0 - if - start_row == end_row - and current_lines[start_row] - and #lines > 0 - and vim.startswith(lines[1], current_lines[start_row]) - then - virt_text_win_col = #current_lines[start_row] - lines[1] = string.sub(lines[1], #current_lines[start_row] + 1) + if start_row == end_row and current_lines[start_row] and #lines > 0 then + if vim.startswith(lines[1], current_lines[start_row]) then + virt_text_win_col = #current_lines[start_row] + lines[1] = string.sub(lines[1], #current_lines[start_row] + 1) + else + local patch = vim.diff( + current_lines[start_row], + lines[1], + ---@diagnostic disable-next-line: missing-fields + { algorithm = "histogram", result_type = "indices", ctxlen = vim.o.scrolloff } + ) + Utils.debug("patch", patch) + if patch and #patch > 0 then + virt_text_win_col = patch[1][3] + lines[1] = string.sub(lines[1], patch[1][3] + 1) + end + end end local virt_lines = {}