Skip to content

Commit c9d18ea

Browse files
committed
fix(scroll): schedule the next scroll instead of just interrupting
1 parent 059f915 commit c9d18ea

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

lua/cinnamon/scroll.lua

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ H.scroller = {
2222
-- Lock the function to prevent re-entrancy. Must be first.
2323
if self.locked then
2424
self.interrupted = true
25+
vim.schedule(function()
26+
self:init(command, options)
27+
end)
2528
return
2629
end
2730
self.locked = true
@@ -76,7 +79,6 @@ H.scroller = {
7679
and original_buffer_id == self.buffer_id
7780
and original_window_id == self.window_id
7881
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
8082
and (not self.options.max_delta.line or (math.abs(self.error.line) <= self.options.max_delta.line))
8183
and (not self.options.max_delta.column or (math.abs(self.error.col) <= self.options.max_delta.column))
8284
then
@@ -200,24 +202,17 @@ H.scroller = {
200202
and math.abs(self.error.winline) < 1
201203
and math.abs(self.error.wincol) < 1
202204
then
205+
self:move_to_target()
203206
self:stop()
204207
return
205208
end
206209
end,
207210

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")
216214
end
217215

218-
vim.wo[self.window_id].scrolloff = self.saved_scrolloff
219-
vim.wo[self.window_id].virtualedit = self.saved_virtualedit
220-
221216
-- The 'curswant' value has to be set with cursor() for the '$' movement.
222217
-- Setting it with winrestview() causes issues when within 'scrolloff'.
223218
vim.api.nvim_win_call(self.window_id, function()
@@ -227,9 +222,25 @@ H.scroller = {
227222
self.target_view.coladd,
228223
self.target_view.curswant + 1,
229224
})
230-
vim.cmd.redraw() -- Cursor isn't redrawn if the window was exited
231225
end)
232226

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+
233244
vim.api.nvim_exec_autocmds("User", { pattern = "CinnamonScrollPost" })
234245
self:cleanup()
235246
end,
@@ -242,7 +253,6 @@ H.scroller = {
242253
utils.notify("Error executing callback: " .. message, "warn")
243254
end
244255
end
245-
self.prev_now = utils.uv.now()
246256
self.locked = false
247257
end,
248258
}

0 commit comments

Comments
 (0)