refactor(jump): only do extra search for target if there was no jump#2303
refactor(jump): only do extra search for target if there was no jump#2303abeldekat wants to merge 1 commit intonvim-mini:mainfrom
Conversation
Details: Instead of always checking if target exists in text, only do so if there was no jump. Additional benefit: The code using the cursor to check if a jump occurred can be replaced by a more direct check
|
The solution applied to solve issue #688 in February 2024 had a side-effect regarding highlighting. Relevant part of diff: @@ -364,6 +365,10 @@ H.make_expr_jump = function(backward, till)
if target == nil then return '<Esc>' end
H.update_state(target, backward, till, vim.v.count1)
+ vim.schedule(function()
+ if H.cache.has_changed_cursor then return end
+ vim.cmd('undo' .. (vim.fn.has('nvim-0.8') == 1 and '!' or ''))
+ end)
return 'v<Cmd>lua MiniJump.jump()<CR>'
Whilst the scheduled Scenario with file containing a single word:
Using its previous commit '1d49300d50a2'
Using the fix, commit '4f69339'
To restore the original highlighting: diff --git a/lua/mini/jump.lua b/lua/mini/jump.lua
index 234510b9..7bf50dd6 100644
--- a/lua/mini/jump.lua
+++ b/lua/mini/jump.lua
@@ -239,7 +239,8 @@ MiniJump.jump = function(target, backward, till, n_times)
-- Ensure to undo "consuming a character" effect if there is no target found
-- Do it here to also act on dot-repeat
if has_jumped or not is_expr then return end
- vim.schedule(function() vim.cmd('undo!') end)
+ -- vim.schedule(function() vim.cmd('undo!') end)
+ vim.api.nvim_create_autocmd('ModeChanged', { once = true, callback = function() vim.cmd('un
do!') end })
end
--- Make smart jumpI think it also is more precise to use the |
|
Thanks for the PR! I'll take a closer look a bit later (probably next week), as I can not quickly see if the new approach is optimal. Should be, as tests pass and it is negative diff 💪
I don't really understand why |
Details:
Instead of always checking if target exists in text, only do so if there was no jump.
Additional benefit: The code using the cursor to check if a jump occurred can be replaced by a more direct check