@@ -11,7 +11,8 @@ local timer = nil
1111local EVENT_TRIGGER = nil
1212local AFTER_DELAY = 1
1313
14- local function move_cursor (trigger )
14+ local function move_cursor (trigger , jump )
15+ -- Calls to this function must deferred for screen.get_screen_cursor_position() and vim.api.nvim.get_mode() to work
1516 trigger = trigger or EVENT_TRIGGER
1617 local row , col
1718 local mode = vim .api .nvim_get_mode ().mode
@@ -30,7 +31,11 @@ local function move_cursor(trigger)
3031 end
3132
3233 if trigger == AFTER_DELAY and mode == latest_mode and row == latest_row and col == latest_col then
33- animation .change_target_position (row , col )
34+ if jump then
35+ animation .jump (row , col )
36+ else
37+ animation .change_target_position (row , col )
38+ end
3439 else -- try until the cursor stops moving
3540 latest_mode = mode
3641 latest_row = row
@@ -41,34 +46,28 @@ local function move_cursor(trigger)
4146 config .delay_event_to_smear ,
4247 0 ,
4348 vim .schedule_wrap (function ()
44- move_cursor (AFTER_DELAY )
49+ move_cursor (AFTER_DELAY , jump )
4550 end )
4651 )
4752 end
4853end
4954
50- M .move_cursor = function (trigger )
51- -- Must defer for screen.get_screen_cursor_position() and vim.api.nvim.get_mode()
55+ M .move_cursor = function ()
5256 vim .defer_fn (function ()
53- move_cursor (trigger )
57+ move_cursor (EVENT_TRIGGER , false )
5458 end , 0 )
5559end
5660
57- local function jump_cursor ()
58- local row , col = screen .get_screen_cursor_position ()
59- animation .jump (row , col )
61+ M .move_cursor_insert_mode = function ()
62+ vim .defer_fn (function ()
63+ move_cursor (EVENT_TRIGGER , not config .smear_insert_mode )
64+ end , 0 )
6065end
6166
6267M .jump_cursor = function ()
63- vim .defer_fn (jump_cursor , 0 ) -- for screen.get_screen_cursor_position()
64- end
65-
66- M .move_cursor_insert_mode = function (trigger )
67- if config .smear_insert_mode then
68- M .move_cursor (trigger )
69- else
70- M .jump_cursor ()
71- end
68+ vim .defer_fn (function ()
69+ move_cursor (EVENT_TRIGGER , true )
70+ end , 0 )
7271end
7372
7473M .listen = function ()
@@ -77,8 +76,9 @@ M.listen = function()
7776 augroup SmearCursor
7877 autocmd!
7978 autocmd CursorMoved,CursorMovedI * lua require("smear_cursor.color").update_color_at_cursor()
80- autocmd CmdlineChanged,CursorMoved,ModeChanged,WinScrolled * lua require("smear_cursor.events").move_cursor(nil)
81- autocmd CursorMovedI * lua require("smear_cursor.events").move_cursor_insert_mode(nil)
79+ autocmd CursorMoved,ModeChanged,WinScrolled * lua require("smear_cursor.events").move_cursor()
80+ autocmd CursorMovedI * lua require("smear_cursor.events").move_cursor_insert_mode()
81+ autocmd CmdlineChanged * lua require("smear_cursor.events").jump_cursor()
8282 autocmd ColorScheme * lua require("smear_cursor.color").clear_cache()
8383 augroup END
8484 ]] ,
0 commit comments