File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,9 @@ M.time_interval = 17 -- milliseconds
5757-- Increase if the cursor makes weird jumps when hitting keys.
5858M .delay_event_to_smear = 1 -- milliseconds
5959
60+ -- Delay for `vim.on_key` to avoid redundancy with vim events triggers.
61+ M .delay_after_key = 1 -- milliseconds
62+
6063-- Smear configuration ---------------------------------------------------------
6164
6265-- How fast the smear's head moves towards the target.
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ local latest_mode = nil
77local latest_row = nil
88local latest_col = nil
99local timer = nil
10+ local cursor_namespace = vim .api .nvim_create_namespace (" smear_cursor" )
1011
1112local EVENT_TRIGGER = nil
1213local AFTER_DELAY = 1
@@ -29,6 +30,7 @@ local function move_cursor(trigger, jump)
2930 timer :stop ()
3031 timer :close ()
3132 end
33+ timer = nil
3234
3335 if trigger == AFTER_DELAY and mode == latest_mode and row == latest_row and col == latest_col then
3436 if jump then
@@ -70,6 +72,12 @@ M.jump_cursor = function()
7072 end , 0 )
7173end
7274
75+ local function on_key (key , typed )
76+ vim .defer_fn (function ()
77+ if timer == nil then M .move_cursor () end
78+ end , config .delay_after_key )
79+ end
80+
7381M .listen = function ()
7482 vim .api .nvim_exec2 (
7583 [[
@@ -85,6 +93,9 @@ M.listen = function()
8593 {}
8694 )
8795
96+ -- To catch changes that do not trigger events (e.g. opening/closing folds)
97+ vim .on_key (on_key , cursor_namespace )
98+
8899 if # config .filetypes_disabled > 0 then
89100 vim .api .nvim_exec2 (
90101 [[
@@ -107,6 +118,8 @@ M.unlisten = function()
107118 ]] ,
108119 {}
109120 )
121+
122+ vim .on_key (nil , cursor_namespace )
110123end
111124
112125return M
You can’t perform that action at this time.
0 commit comments