Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: suggetion in the middle of line #1094

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions lua/avante/suggestion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {}
Expand Down
Loading