Skip to content

Commit d1c6c18

Browse files
committed
Merge branch 'main' into fix-range-sel
2 parents 8fe7b1a + e0a7b5a commit d1c6c18

File tree

5 files changed

+23
-36
lines changed

5 files changed

+23
-36
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ local ts_repeat_move = require "nvim-treesitter-textobjects.repeatable_move"
170170

171171
-- Repeat movement with ; and ,
172172
-- ensure ; goes forward and , goes backward regardless of the last direction
173-
vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next)
174-
vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous)
173+
vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next, { expr = true })
174+
vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous, { expr = true })
175175

176176
-- vim way: ; goes to the direction you were moving.
177177
-- vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move)

lua/nvim-treesitter-textobjects/repeatable_move.lua

+11-26
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,19 @@ M.make_repeatable_move = function(move_fn)
2727
end
2828

2929
---@param opts_extend TSTextObjects.MoveOpts?
30-
---@return boolean
30+
---@return string?
3131
M.repeat_last_move = function(opts_extend)
32-
if M.last_move then
33-
local opts ---@type table
34-
if opts_extend ~= nil then
35-
opts = vim.tbl_deep_extend("force", {}, M.last_move.opts, opts_extend)
36-
else
37-
opts = M.last_move.opts
38-
end
39-
40-
if M.last_move.func == "f" or M.last_move.func == "t" then
41-
if opts.forward then
42-
vim.cmd.normal { vim.v.count1 .. ";", bang = true }
43-
else
44-
vim.cmd.normal { vim.v.count1 .. ",", bang = true }
45-
end
46-
elseif M.last_move.func == "F" or M.last_move.func == "T" then
47-
if opts.forward then
48-
vim.cmd.normal { vim.v.count1 .. ",", bang = true }
49-
else
50-
vim.cmd.normal { vim.v.count1 .. ";", bang = true }
51-
end
52-
else
53-
M.last_move.func(opts, unpack(M.last_move.additional_args))
54-
end
55-
return true
32+
if not M.last_move then
33+
return
34+
end
35+
local opts = vim.tbl_deep_extend("force", M.last_move.opts, opts_extend or {})
36+
if M.last_move.func == "f" or M.last_move.func == "t" then
37+
return opts.forward and ";" or ","
38+
elseif M.last_move.func == "F" or M.last_move.func == "T" then
39+
return opts.forward and "," or ";"
40+
else
41+
return M.last_move.func(opts, unpack(M.last_move.additional_args))
5642
end
57-
return false
5843
end
5944

6045
M.repeat_last_move_opposite = function()

queries/julia/textobjects.scm

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
.
1313
(_) @block.inner
1414
(_)? @block.inner .)
15-
)
15+
1616
(let_statement) @block.outer
1717

1818
(let_statement
1919
.
2020
(_) @block.inner
2121
(_)? @block.inner .)
22-
)
22+
2323
; Conditionals
2424
(if_statement
2525
condition: (_) @conditional.inner) @conditional.outer
@@ -49,7 +49,7 @@
4949
.
5050
(_) @conditional.inner
5151
(_)? @conditional.inner .)
52-
)
52+
5353
; Loops
5454
(for_statement) @loop.outer
5555

@@ -75,7 +75,7 @@
7575
.
7676
(_) @class.inner
7777
(_)? @class.inner .)
78-
)
78+
7979
; Function definitions
8080
(function_definition) @function.outer
8181

scripts/minimal_init.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,14 @@ end)
394394

395395
-- Repeat movement with ; and ,
396396
-- ensure ; goes forward and , goes backward regardless of the last direction
397-
-- vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next)
398-
-- vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous)
397+
-- vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next, { expr = true })
398+
-- vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous, { expr = true })
399399

400400
local repeat_move = require "nvim-treesitter-textobjects.repeatable_move"
401401

402402
-- vim way: ; goes to the direction you were moving.
403-
vim.keymap.set({ "n", "x", "o" }, ";", repeat_move.repeat_last_move)
404-
vim.keymap.set({ "n", "x", "o" }, ",", repeat_move.repeat_last_move_opposite)
403+
vim.keymap.set({ "n", "x", "o" }, ";", repeat_move.repeat_last_move, { expr = true })
404+
vim.keymap.set({ "n", "x", "o" }, ",", repeat_move.repeat_last_move_opposite, { expr = true })
405405

406406
-- Optionally, make builtin f, F, t, T also repeatable with ; and ,
407407
vim.keymap.set({ "n", "x", "o" }, "f", repeat_move.builtin_f_expr, { expr = true })

tests/select/python_spec.lua

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ describe("command equality Python:", function()
2121
})
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" } })
24+
-- repeatable move should work like default behavior (#699)
25+
run:compare_cmds("aligned_indent.py", { row = 1, col = 0, cmds = { "dfn", "d;" } })
2426
-- select using move
2527
run:compare_cmds("aligned_indent.py", { row = 1, col = 0, cmds = { "d]a", "v]ad", "c]a" } })
2628
run:compare_cmds("selection_mode.py", { row = 2, col = 4, cmds = { "dam", "dVam", "vamd", "Vamd" } })

0 commit comments

Comments
 (0)