From fc3f0041fbe01c96f38224d65d27664b22b5ef78 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 27 Sep 2026 11:40:30 -0400 Subject: fix(editor)!: operator target/cgn modifies Visual marks #42119 Problem: An operator on a target that creates a Visual selection (`cgn`, `dj`, an omap text object like `: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. --- runtime/lua/vim/treesitter/_select.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'runtime/lua/vim/treesitter/_select.lua') diff --git a/runtime/lua/vim/treesitter/_select.lua b/runtime/lua/vim/treesitter/_select.lua index afdd1a7612..6708e6292f 100644 --- a/runtime/lua/vim/treesitter/_select.lua +++ b/runtime/lua/vim/treesitter/_select.lua @@ -356,7 +356,8 @@ local function get_selection() pos1, pos2 = pos2, pos1 end - if vim.o.selection == 'exclusive' then + -- selection=exclusive excludes end char, except for empty selection (op-pending, or a new "v"). + if vim.o.selection == 'exclusive' and (pos1[2] ~= pos2[2] or pos1[3] ~= pos2[3]) then pos2[3] = pos2[3] - 1 end -- cgit