diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2026-09-27 11:40:30 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-27 11:40:30 -0400 |
| commit | fc3f0041fbe01c96f38224d65d27664b22b5ef78 (patch) | |
| tree | affdee09d7616e9af4658a8afe3c090b718d9ca4 /runtime/lua/vim/treesitter/_range.lua | |
| parent | c216c557fd76c762aa11486ed78e5897a96e6efc (diff) | |
| download | rneovim-fc3f0041fbe01c96f38224d65d27664b22b5ef78.tar.gz rneovim-fc3f0041fbe01c96f38224d65d27664b22b5ef78.tar.bz2 rneovim-fc3f0041fbe01c96f38224d65d27664b22b5ef78.zip | |
fix(editor)!: operator target/cgn modifies Visual marks #42119
Problem:
An operator on a target that creates a Visual selection (`cgn`,
`d<C-v>j`, an omap text object like `:<C-U>normal! viw`) sets `'< '>`,
`gv` and `visualmode()` to the operator target.
This causes at least the following problems:
- clobbers the user's previous `'< '>` (annoying and usually unwanted)
- E.g. after a custom textobj, `:help text-object-define`.
- "cgn" with a `\%V` pattern can't be dot-repeated (".")
Solution:
Don't save the Visual area if the operator target created it (operator
was pending).
Also fix `an`/`in` with `'selection'=exclusive` starting from an empty
range.
Diffstat (limited to 'runtime/lua/vim/treesitter/_range.lua')
| -rw-r--r-- | runtime/lua/vim/treesitter/_range.lua | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/runtime/lua/vim/treesitter/_range.lua b/runtime/lua/vim/treesitter/_range.lua index ab322e8188..1526acb8aa 100644 --- a/runtime/lua/vim/treesitter/_range.lua +++ b/runtime/lua/vim/treesitter/_range.lua @@ -186,6 +186,18 @@ function M.visual_select(range) end_col = #vim.fn.getline(end_row + 1) + 1 end + if vim.o.selection == 'exclusive' then + end_col = end_col + 1 + end + + if not vim.fn.mode():find('^[vV\22]') then + -- Operator-pending: select directly, not via "gv", to keep the user's '< '> (|omap-info|). + api.nvim_win_set_cursor(0, { start_row + 1, start_col }) + vim.cmd.normal({ 'v', bang = true }) + api.nvim_win_set_cursor(0, { end_row + 1, end_col - 1 }) + return + end + if vim.fn.visualmode() ~= 'v' then -- Reset visualmode() to 'v' vim.cmd.normal({ 'v\27', bang = true }) @@ -198,10 +210,6 @@ function M.visual_select(range) cursor_other_end_of_selection = true end - if vim.o.selection == 'exclusive' then - end_col = end_col + 1 - end - vim.fn.setpos("'<", { 0, start_row + 1, start_col + 1, 0 }) vim.fn.setpos("'>", { 0, end_row + 1, end_col, 0 }) |