refactor(treesitter): use same visual-select as lsp #38475

Problem
treesitter select over-complicates visual selection.

Solution
make it use same visual selection logic as lsp.
This commit is contained in:
altermo
2026-03-25 10:20:42 +01:00
committed by GitHub
parent 40a42affa5
commit 170ff4b244

View File

@@ -353,23 +353,23 @@ local function visual_select(range)
local srow, scol, erow, ecol = Range.unpack4(range)
local cursor_other_end_of_visual = false
if vim.fn.mode() == 'v' then
local vcol, vrow = vim.fn.col('v'), vim.fn.line('v')
local ccol, cline = vim.fn.col('.'), vim.fn.line('.')
if vrow > cline or (vrow == cline and vcol > ccol) then
cursor_other_end_of_visual = true
end
local vcol, vrow = vim.fn.col('v'), vim.fn.line('v')
local ccol, cline = vim.fn.col('.'), vim.fn.line('.')
if vrow > cline or (vrow == cline and vcol > ccol) then
cursor_other_end_of_visual = true
end
vim.api.nvim_win_set_cursor(0, { srow + 1, scol })
vim.api.nvim_feedkeys(vim.keycode('<C-\\><C-n>v'), 'nx', true)
if not pcall(vim.api.nvim_win_set_cursor, 0, { erow + 1, ecol - 1 }) then
vim.api.nvim_win_set_cursor(0, { erow, #vim.fn.getline(erow) })
if ecol == 0 then
erow = erow - 1
ecol = #vim.fn.getline(erow + 1) + 1
end
vim.fn.setpos("'<", { 0, srow + 1, scol + 1, 0 })
vim.fn.setpos("'>", { 0, erow + 1, ecol, 0 })
if cursor_other_end_of_visual then
vim.api.nvim_feedkeys('o', 'nx', true)
vim.cmd.normal({ 'gvo', bang = true })
else
vim.cmd.normal({ 'gv', bang = true })
end
end