fix(scroll): stop animations when buf/changedtick changes

This commit is contained in:
Folke Lemaitre 2025-10-23 21:24:33 +02:00
parent 1f2b8b765e
commit a42b3761f7
No known key found for this signature in database
GPG key ID: 9B52594D560070AB

View file

@ -302,11 +302,22 @@ function M.check(win)
or (state.target.topline == state.current.topline and state.target.topfill < state.current.topfill)
local scrolled = 0
local changedtick = state.changedtick
local buf = vim.api.nvim_win_get_buf(win)
state.anim = Snacks.animate(0, scrolls, function(value, ctx)
if not vim.api.nvim_win_is_valid(win) then
return
end
if not vim.api.nvim_buf_is_valid(buf) or buf ~= vim.api.nvim_win_get_buf(win) then
return
end
if vim.b[state.buf].changedtick ~= changedtick then
return
end
vim.api.nvim_win_call(win, function()
if ctx.done then
vim.fn.winrestview(state.target)