@@ -22,6 +22,9 @@ H.scroller = {
22
22
-- Lock the function to prevent re-entrancy. Must be first.
23
23
if self .locked then
24
24
self .interrupted = true
25
+ vim .schedule (function ()
26
+ self :init (command , options )
27
+ end )
25
28
return
26
29
end
27
30
self .locked = true
@@ -76,7 +79,6 @@ H.scroller = {
76
79
and original_buffer_id == self .buffer_id
77
80
and original_window_id == self .window_id
78
81
and (not self .window_only or H .window_scrolled (original_view , self .target_view ))
79
- and (self .prev_now == nil or (utils .uv .now () - self .prev_now ) > 100 ) -- Not a held key
80
82
and (not self .options .max_delta .line or (math.abs (self .error .line ) <= self .options .max_delta .line ))
81
83
and (not self .options .max_delta .column or (math.abs (self .error .col ) <= self .options .max_delta .column ))
82
84
then
@@ -200,24 +202,17 @@ H.scroller = {
200
202
and math.abs (self .error .winline ) < 1
201
203
and math.abs (self .error .wincol ) < 1
202
204
then
205
+ self :move_to_target ()
203
206
self :stop ()
204
207
return
205
208
end
206
209
end ,
207
210
208
- stop = function (self )
209
- self .scroll_scheduler :close ()
210
- self .timeout_timer :close ()
211
-
212
- if self .window_only then
213
- -- Restore the cursor
214
- vim .cmd (" highlight Cursor blend=0" )
215
- vim .opt .guicursor :remove ({ " a:Cursor/lCursor" })
211
+ move_to_target = function (self )
212
+ if self .target_view == nil then
213
+ error (" Target view has not been set" )
216
214
end
217
215
218
- vim .wo [self .window_id ].scrolloff = self .saved_scrolloff
219
- vim .wo [self .window_id ].virtualedit = self .saved_virtualedit
220
-
221
216
-- The 'curswant' value has to be set with cursor() for the '$' movement.
222
217
-- Setting it with winrestview() causes issues when within 'scrolloff'.
223
218
vim .api .nvim_win_call (self .window_id , function ()
@@ -227,9 +222,25 @@ H.scroller = {
227
222
self .target_view .coladd ,
228
223
self .target_view .curswant + 1 ,
229
224
})
230
- vim .cmd .redraw () -- Cursor isn't redrawn if the window was exited
231
225
end )
232
226
227
+ -- Cursor isn't redrawn if the window was exited
228
+ vim .cmd .redraw ()
229
+ end ,
230
+
231
+ stop = function (self )
232
+ self .scroll_scheduler :close ()
233
+ self .timeout_timer :close ()
234
+
235
+ if self .window_only then
236
+ -- Restore the cursor
237
+ vim .cmd (" highlight Cursor blend=0" )
238
+ vim .opt .guicursor :remove ({ " a:Cursor/lCursor" })
239
+ end
240
+
241
+ vim .wo [self .window_id ].scrolloff = self .saved_scrolloff
242
+ vim .wo [self .window_id ].virtualedit = self .saved_virtualedit
243
+
233
244
vim .api .nvim_exec_autocmds (" User" , { pattern = " CinnamonScrollPost" })
234
245
self :cleanup ()
235
246
end ,
@@ -242,7 +253,6 @@ H.scroller = {
242
253
utils .notify (" Error executing callback: " .. message , " warn" )
243
254
end
244
255
end
245
- self .prev_now = utils .uv .now ()
246
256
self .locked = false
247
257
end ,
248
258
}
0 commit comments