fix: suggetion in the middle of line (#1094)

This commit is contained in:
yetone 2025-01-16 21:39:11 +08:00 committed by GitHub
parent ac6bf35616
commit da4ef9d9e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -206,6 +206,8 @@ L5: pass
end end
function Suggestion:show() function Suggestion:show()
Utils.debug("showing suggestions, mode:", fn.mode())
self:hide() self:hide()
if not fn.mode():match("^[iR]") then return end if not fn.mode():match("^[iR]") then return end
@ -231,14 +233,23 @@ function Suggestion:show()
local virt_text_win_col = 0 local virt_text_win_col = 0
if if start_row == end_row and current_lines[start_row] and #lines > 0 then
start_row == end_row if vim.startswith(lines[1], current_lines[start_row]) then
and current_lines[start_row] virt_text_win_col = #current_lines[start_row]
and #lines > 0 lines[1] = string.sub(lines[1], #current_lines[start_row] + 1)
and vim.startswith(lines[1], current_lines[start_row]) else
then local patch = vim.diff(
virt_text_win_col = #current_lines[start_row] current_lines[start_row],
lines[1] = string.sub(lines[1], #current_lines[start_row] + 1) 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 end
local virt_lines = {} local virt_lines = {}