Skip to content

Commit

Permalink
fix(scroll): schedule the next scroll instead of just interrupting
Browse files Browse the repository at this point in the history
  • Loading branch information
declancm committed Jul 21, 2024
1 parent 059f915 commit c9d18ea
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions lua/cinnamon/scroll.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ H.scroller = {
-- Lock the function to prevent re-entrancy. Must be first.
if self.locked then
self.interrupted = true
vim.schedule(function()
self:init(command, options)
end)
return
end
self.locked = true
Expand Down Expand Up @@ -76,7 +79,6 @@ H.scroller = {
and original_buffer_id == self.buffer_id
and original_window_id == self.window_id
and (not self.window_only or H.window_scrolled(original_view, self.target_view))
and (self.prev_now == nil or (utils.uv.now() - self.prev_now) > 100) -- Not a held key
and (not self.options.max_delta.line or (math.abs(self.error.line) <= self.options.max_delta.line))
and (not self.options.max_delta.column or (math.abs(self.error.col) <= self.options.max_delta.column))
then
Expand Down Expand Up @@ -200,24 +202,17 @@ H.scroller = {
and math.abs(self.error.winline) < 1
and math.abs(self.error.wincol) < 1
then
self:move_to_target()
self:stop()
return
end
end,

stop = function(self)
self.scroll_scheduler:close()
self.timeout_timer:close()

if self.window_only then
-- Restore the cursor
vim.cmd("highlight Cursor blend=0")
vim.opt.guicursor:remove({ "a:Cursor/lCursor" })
move_to_target = function(self)
if self.target_view == nil then
error("Target view has not been set")
end

vim.wo[self.window_id].scrolloff = self.saved_scrolloff
vim.wo[self.window_id].virtualedit = self.saved_virtualedit

-- The 'curswant' value has to be set with cursor() for the '$' movement.
-- Setting it with winrestview() causes issues when within 'scrolloff'.
vim.api.nvim_win_call(self.window_id, function()
Expand All @@ -227,9 +222,25 @@ H.scroller = {
self.target_view.coladd,
self.target_view.curswant + 1,
})
vim.cmd.redraw() -- Cursor isn't redrawn if the window was exited
end)

-- Cursor isn't redrawn if the window was exited
vim.cmd.redraw()
end,

stop = function(self)
self.scroll_scheduler:close()
self.timeout_timer:close()

if self.window_only then
-- Restore the cursor
vim.cmd("highlight Cursor blend=0")
vim.opt.guicursor:remove({ "a:Cursor/lCursor" })
end

vim.wo[self.window_id].scrolloff = self.saved_scrolloff
vim.wo[self.window_id].virtualedit = self.saved_virtualedit

vim.api.nvim_exec_autocmds("User", { pattern = "CinnamonScrollPost" })
self:cleanup()
end,
Expand All @@ -242,7 +253,6 @@ H.scroller = {
utils.notify("Error executing callback: " .. message, "warn")
end
end
self.prev_now = utils.uv.now()
self.locked = false
end,
}
Expand Down

0 comments on commit c9d18ea

Please sign in to comment.