mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-06 11:48:23 +00:00
feat(scroll): improve smooth scrolling when user is spamming keys
This commit is contained in:
parent
7c7b18fdee
commit
5532ba07be
1 changed files with 11 additions and 8 deletions
|
@ -205,19 +205,22 @@ function M.check(win)
|
||||||
stats.skipped = stats.skipped + 1
|
stats.skipped = stats.skipped + 1
|
||||||
state.current = vim.deepcopy(state.view)
|
state.current = vim.deepcopy(state.view)
|
||||||
return
|
return
|
||||||
elseif mouse_scrolling or spamming then
|
elseif spamming and not (state.anim and state.anim.done) then
|
||||||
|
-- just ignore the scroll when spamming and we're already animating
|
||||||
|
stats.spamming = stats.spamming + 1
|
||||||
|
stats.scrolls = stats.scrolls + 1
|
||||||
|
vim.api.nvim_win_call(win, function()
|
||||||
|
vim.fn.winrestview(state.current)
|
||||||
|
end)
|
||||||
|
return
|
||||||
|
elseif mouse_scrolling then
|
||||||
if state.anim then
|
if state.anim then
|
||||||
state.anim:stop()
|
state.anim:stop()
|
||||||
state.anim = nil
|
state.anim = nil
|
||||||
virtualedit(state) -- restore virtualedit
|
virtualedit(state) -- restore virtualedit
|
||||||
end
|
end
|
||||||
if mouse_scrolling then
|
mouse_scrolling = false
|
||||||
mouse_scrolling = false
|
stats.mousescroll = stats.mousescroll + 1
|
||||||
stats.mousescroll = stats.mousescroll + 1
|
|
||||||
else -- spamming
|
|
||||||
stats.spamming = stats.spamming + 1
|
|
||||||
stats.scrolls = stats.scrolls + 1
|
|
||||||
end
|
|
||||||
state.current = vim.deepcopy(state.view)
|
state.current = vim.deepcopy(state.view)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue