fix(jump): consumes a char on dot-repeat when target not in text#2291
Conversation
|
I wonder if the vim.schedule for undo could also be achieved with a one-time mode change event. |
|
Thanks for the PR! My initial impression is that the change does more than is needed to fix the described issue. Or it fixes more than described in the commit or issue. Because the part of "works on first try but doesn't work on dot-repeat" is probably meant to be fixed by moving the logic from I think the following should fix the issue: diff --git a/lua/mini/jump.lua b/lua/mini/jump.lua
index 3ac813d8..7165a1bf 100644
--- a/lua/mini/jump.lua
+++ b/lua/mini/jump.lua
@@ -181,6 +181,14 @@ MiniJump.state = {
MiniJump.jump = function(target, backward, till, n_times)
if H.is_disabled() then return end
+ -- Ensure to undo "consuming a character" effect if there is no target found
+ -- Do it here to act on dot-repeat
+ local has_changed_cursor = false
+ local undo_no_move = function()
+ if not has_changed_cursor then vim.cmd('undo!') end
+ end
+ if MiniJump._is_expr then vim.schedule(undo_no_move) end
+
-- Dot-repeat should not change the state, so save it to later restore
local is_dot_repeat = MiniJump._is_expr and not MiniJump._is_expr_init
MiniJump._is_expr, MiniJump._is_expr_init = nil, nil
@@ -234,7 +242,7 @@ MiniJump.jump = function(target, backward, till, n_times)
-- Track cursor position to account for movement not caught by `CursorMoved`
H.cache.latest_cursor = H.get_cursor_data()
- H.cache.has_changed_cursor = not vim.deep_equal(H.cache.latest_cursor, init_cursor_data)
+ has_changed_cursor = not vim.deep_equal(H.cache.latest_cursor, init_cursor_data)
-- Restore the state if needed
if is_dot_repeat then
@@ -404,11 +412,6 @@ H.make_expr_jump = function(backward, till)
if isnt_repeat_jump and target == nil then return '<Esc>' end
H.update_state(target)
- vim.schedule(function()
- if H.cache.has_changed_cursor then return end
- vim.cmd('undo!')
- end)
-
-- Set a flag to distinguish first call from dot-repeat
MiniJump._is_expr_init = true
|
Yes, you are right. I even started with another version of your approach. Whilst working on the issue, I encountered behavior which I thought to be a bug. Only on the last moment I saw that it was to be expected, also understanding this test. Because of that misperception, I thought I needed to get rid of this early return. I submitted the current version because it worked and I think it has two main benefits:
Would you like me to resubmit with your version? |
Both of these are nice improvements, but they are not about fixing the issue. It is hard to see if the approach is good if it does several things at once (i.e. fixes the issue and refactors the code to address two points above). I am not opposed to refactor but it needs to be a separate commit that doesn't touch tests and still passes them. So I think following "as less diff as possible" while fixing the issue is a better approach here. If my above diff works, let's use it at least for now. |
0fc45fa to
7f1a727
Compare
Done. Would you accept a refactoring pr? |
Maybe after this is merged. But there are some other things in |
|
Since tests fail on Nightly (due to upstream neovim/neovim#38137), I've merged into temporary branch to polish and push manually. Thanks again for noticing the issue and doing the PR! Edit: Should now be part of the |
Resolve #2290