fix: get selection range from previous visual mode (#689)
This commit is contained in:
@@ -161,7 +161,7 @@ function M.trim(str, opts)
|
||||
end
|
||||
|
||||
function M.in_visual_mode()
|
||||
local current_mode = vim.fn.mode()
|
||||
local current_mode = fn.mode()
|
||||
return current_mode == "v" or current_mode == "V" or current_mode == ""
|
||||
end
|
||||
|
||||
@@ -171,10 +171,15 @@ function M.get_visual_selection_and_range()
|
||||
local Range = require("avante.range")
|
||||
local SelectionResult = require("avante.selection_result")
|
||||
|
||||
if not M.in_visual_mode() then return nil end
|
||||
-- Get the start and end positions of Visual mode
|
||||
local start_pos = vim.fn.getpos("v")
|
||||
local end_pos = vim.fn.getpos(".")
|
||||
local start_pos = fn.getpos("v")
|
||||
local end_pos = fn.getpos(".")
|
||||
|
||||
if not M.in_visual_mode() then
|
||||
start_pos = fn.getpos("'<")
|
||||
end_pos = fn.getpos("'>")
|
||||
end
|
||||
|
||||
-- Get the start and end line and column numbers
|
||||
local start_line = start_pos[2]
|
||||
local start_col = start_pos[3]
|
||||
@@ -190,12 +195,12 @@ function M.get_visual_selection_and_range()
|
||||
-- Check if it's a single-line selection
|
||||
if start_line == end_line then
|
||||
-- Get partial content of a single line
|
||||
local line = vim.fn.getline(start_line)
|
||||
local line = fn.getline(start_line)
|
||||
-- content = string.sub(line, start_col, end_col)
|
||||
content = line
|
||||
else
|
||||
-- Multi-line selection: Get all lines in the selection
|
||||
local lines = vim.fn.getline(start_line, end_line)
|
||||
local lines = fn.getline(start_line, end_line)
|
||||
-- Extract partial content of the first line
|
||||
-- lines[1] = string.sub(lines[1], start_col)
|
||||
-- Extract partial content of the last line
|
||||
|
||||
Reference in New Issue
Block a user