fix: AvanteEdit highlight for visual line mode (#326)

This commit is contained in:
Brent Yi 2024-08-28 08:46:26 -07:00 committed by GitHub
parent 1c0623a9df
commit 2c450b1da3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -283,22 +283,29 @@ function Selection:create_editing_input()
self.selection = Utils.get_visual_selection_and_range() self.selection = Utils.get_visual_selection_and_range()
local end_row = self.selection.range.finish.line - 1 local start_row
local end_col = math.min(self.selection.range.finish.col, #code_lines[self.selection.range.finish.line]) local start_col
local end_row
local end_col
if vim.fn.mode() == "V" then
start_row = self.selection.range.start.line - 1
start_col = 0
end_row = self.selection.range.finish.line - 1
end_col = #code_lines[self.selection.range.finish.line]
else
start_row = self.selection.range.start.line - 1
start_col = self.selection.range.start.col - 1
end_row = self.selection.range.finish.line - 1
end_col = math.min(self.selection.range.finish.col, #code_lines[self.selection.range.finish.line])
end
self.selected_code_extmark_id = api.nvim_buf_set_extmark( self.selected_code_extmark_id = api.nvim_buf_set_extmark(code_bufnr, SELECTED_CODE_NAMESPACE, start_row, start_col, {
code_bufnr,
SELECTED_CODE_NAMESPACE,
self.selection.range.start.line - 1,
self.selection.range.start.col - 1,
{
hl_group = "Visual", hl_group = "Visual",
hl_mode = "combine", hl_mode = "combine",
end_row = end_row, end_row = end_row,
end_col = end_col, end_col = end_col,
priority = PRIORITY, priority = PRIORITY,
} })
)
local bufnr = api.nvim_create_buf(false, true) local bufnr = api.nvim_create_buf(false, true)