Skip to content

Commit 8c47155

Browse files
committed
.
1 parent c5006c4 commit 8c47155

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lua/nvim-treesitter-textobjects/repeatable_move.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,31 @@ M.make_repeatable_move = function(move_fn)
2626
end
2727
end
2828

29+
--- Enter visual mode (nov) if operator-pending (no) mode (fixes #699)
30+
--- Why? According to https://learnvimscriptthehardway.stevelosh.com/chapters/15.html
31+
--- If your operator-pending mapping ends with some text visually selected, Vim will operate on that text.
32+
--- Otherwise, Vim will operate on the text between the original cursor position and the new position.
33+
local function force_operator_pending_visual_mode()
34+
local mode = vim.api.nvim_get_mode()
35+
if mode.mode == 'no' then
36+
vim.cmd.normal({ 'v', bang = true })
37+
end
38+
end
39+
2940
---@param opts_extend TSTextObjects.MoveOpts?
3041
M.repeat_last_move = function(opts_extend)
3142
if not M.last_move then
3243
return
3344
end
3445
local opts = vim.tbl_deep_extend('force', M.last_move.opts, opts_extend or {})
3546
if M.last_move.func == 'f' or M.last_move.func == 't' then
47+
force_operator_pending_visual_mode()
3648
vim.cmd([[normal! ]] .. vim.v.count1 .. (opts.forward and ';' or ','))
3749
elseif M.last_move.func == 'F' or M.last_move.func == 'T' then
50+
force_operator_pending_visual_mode()
3851
vim.cmd([[normal! ]] .. vim.v.count1 .. (opts.forward and ',' or ';'))
3952
else
53+
-- we assume other textobjects (move) already handle operator-pending mode correctly
4054
M.last_move.func(opts, unpack(M.last_move.additional_args))
4155
end
4256
end

tests/select/python_spec.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ describe('command equality Python:', function()
2222
-- select using built-in finds (f, F, t, T)
2323
run:compare_cmds('aligned_indent.py', { row = 1, col = 0, cmds = { 'dfi', 'vfid', 'cfi' } })
2424
-- repeatable move should work like default behavior (#699)
25-
-- FIXME: this is currently broken due to #795 but we coudln't find a good workaround yet.
26-
-- uncomment when fixed.
27-
-- run:compare_cmds('aligned_indent.py', { row = 1, col = 0, cmds = { 'dfn', 'd;' } })
28-
25+
run:compare_cmds('aligned_indent.py', { row = 1, col = 0, cmds = { 'dfn', 'd;' } })
2926
-- select using move
3027
run:compare_cmds('aligned_indent.py', { row = 1, col = 0, cmds = { 'd]a', 'v]ad', 'c]a' } })
3128
run:compare_cmds(

0 commit comments

Comments
 (0)