fix(treesitter): incremental selection causes beeps when the bell is enabled #40414

Problem:  The function visual_select() in treesitter/_select.lua is
          executing `:normal! v<Esc>` to ensure that `gv` later goes
          back to character Visual mode, but doing so when mode() is
          already `v` first switches back to the Normal mode, then
          executes <Esc>, which causes a beep.
Solution: Check if the mode() is already `v` and avoid any switching in
          that case.
This commit is contained in:
Dmytro Meleshko
2026-06-25 17:36:24 +02:00
committed by GitHub
parent 122be61ed2
commit 9afa8477b3

View File

@@ -364,8 +364,10 @@ local function visual_select(range)
ecol = #vim.fn.getline(erow + 1) + 1
end
-- reset visualmode() to 'v'
vim.cmd.normal({ 'v\27', bang = true })
if vim.api.nvim_get_mode().mode ~= 'v' then
-- reset visualmode() to 'v'
vim.cmd.normal({ 'v\27', bang = true })
end
vim.fn.setpos("'<", { 0, srow + 1, scol + 1, 0 })
vim.fn.setpos("'>", { 0, erow + 1, ecol, 0 })