Skip to content

Commit 1b2d85d

Browse files
authored
fix(repeatable_move): bug when nil was returned or normal command used; no longer requires { expr = true } (#795)
Should fix #775 https://github.com/user-attachments/assets/afecce63-6db3-42c8-977b-e1a209ae9c68 Not sure if this fix is already being addressed in another way or refactor process, but just in case, the move_repeatable function was failing when no string was being returned (nil in this case) due to { expr = true } keymap options.
1 parent b54cec3 commit 1b2d85d

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
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, { expr = true })
174-
vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous, { expr = true })
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)
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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@ M.make_repeatable_move = function(move_fn)
2727
end
2828

2929
---@param opts_extend TSTextObjects.MoveOpts?
30-
---@return string?
3130
M.repeat_last_move = function(opts_extend)
3231
if not M.last_move then
3332
return
3433
end
3534
local opts = vim.tbl_deep_extend('force', M.last_move.opts, opts_extend or {})
3635
if M.last_move.func == 'f' or M.last_move.func == 't' then
37-
return opts.forward and ';' or ','
36+
vim.cmd([[normal! ]] .. vim.v.count1 .. (opts.forward and ';' or ','))
3837
elseif M.last_move.func == 'F' or M.last_move.func == 'T' then
39-
return opts.forward and ',' or ';'
38+
vim.cmd([[normal! ]] .. vim.v.count1 .. (opts.forward and ',' or ';'))
4039
else
41-
return M.last_move.func(opts, unpack(M.last_move.additional_args))
40+
M.last_move.func(opts, unpack(M.last_move.additional_args))
4241
end
4342
end
4443

scripts/minimal_init.lua

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require('nvim-treesitter-textobjects').setup({
1616
})
1717

1818
local select = require('nvim-treesitter-textobjects.select')
19+
1920
for _, mode in ipairs({ 'x', 'o' }) do
2021
vim.keymap.set(mode, 'am', function()
2122
select.select_textobject('@function.outer', 'textobjects')
@@ -125,6 +126,7 @@ end)
125126

126127
-- move
127128
local move = require('nvim-treesitter-textobjects.move')
129+
128130
vim.keymap.set({ 'n', 'x', 'o' }, ']m', function()
129131
move.goto_next_start('@function.outer')
130132
end)
@@ -393,19 +395,20 @@ vim.keymap.set({ 'n', 'x', 'o' }, '[[E', function()
393395
move.goto_previous_end('@scopename.inner')
394396
end)
395397

398+
-- repeat
399+
local ts_repeat_move = require('nvim-treesitter-textobjects.repeatable_move')
400+
396401
-- Repeat movement with ; and ,
397402
-- ensure ; goes forward and , goes backward regardless of the last direction
398-
-- vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next, { expr = true })
399-
-- vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous, { expr = true })
400-
401-
local repeat_move = require('nvim-treesitter-textobjects.repeatable_move')
403+
vim.keymap.set({ 'n', 'x', 'o' }, ';', ts_repeat_move.repeat_last_move_next)
404+
vim.keymap.set({ 'n', 'x', 'o' }, ',', ts_repeat_move.repeat_last_move_previous)
402405

403406
-- vim way: ; goes to the direction you were moving.
404-
vim.keymap.set({ 'n', 'x', 'o' }, ';', repeat_move.repeat_last_move, { expr = true })
405-
vim.keymap.set({ 'n', 'x', 'o' }, ',', repeat_move.repeat_last_move_opposite, { expr = true })
407+
-- vim.keymap.set({ 'n', 'x', 'o' }, ';', ts_repeat_move.repeat_last_move)
408+
-- vim.keymap.set({ 'n', 'x', 'o' }, ',', ts_repeat_move.repeat_last_move_opposite)
406409

407410
-- Optionally, make builtin f, F, t, T also repeatable with ; and ,
408-
vim.keymap.set({ 'n', 'x', 'o' }, 'f', repeat_move.builtin_f_expr, { expr = true })
409-
vim.keymap.set({ 'n', 'x', 'o' }, 'F', repeat_move.builtin_F_expr, { expr = true })
410-
vim.keymap.set({ 'n', 'x', 'o' }, 't', repeat_move.builtin_t_expr, { expr = true })
411-
vim.keymap.set({ 'n', 'x', 'o' }, 'T', repeat_move.builtin_T_expr, { expr = true })
411+
vim.keymap.set({ 'n', 'x', 'o' }, 'f', ts_repeat_move.builtin_f_expr, { expr = true })
412+
vim.keymap.set({ 'n', 'x', 'o' }, 'F', ts_repeat_move.builtin_F_expr, { expr = true })
413+
vim.keymap.set({ 'n', 'x', 'o' }, 't', ts_repeat_move.builtin_t_expr, { expr = true })
414+
vim.keymap.set({ 'n', 'x', 'o' }, 'T', ts_repeat_move.builtin_T_expr, { expr = true })

0 commit comments

Comments
 (0)