fix(scroll): stop anim and reset state when win has new buf, or buf was changed. Closes #1820. Closes #2221

This commit is contained in:
Folke Lemaitre 2025-10-22 22:10:38 +02:00
parent 79f3a8d8b3
commit 766f7b87aa
No known key found for this signature in database
GPG key ID: 9B52594D560070AB

View file

@ -87,13 +87,10 @@ local function get_state(win)
local changedtick = vim.api.nvim_buf_get_changedtick(buf)
local view = vim.api.nvim_win_call(win, vim.fn.winsaveview) ---@type vim.fn.winsaveview.ret
if not (states[win] and states[win].buf == buf and states[win].changedtick == changedtick) then
-- go to target if we're still animating and resetting due to a change
if states[win] and states[win].anim and not states[win].anim.done and states[win].buf == buf then
-- new buffer, or buffer changed: cancel existing animation and reset state
if states[win] and states[win].anim then
states[win].anim:stop()
states[win].anim = nil
vim.api.nvim_win_call(win, function()
vim.fn.winrestview(states[win].target)
end)
wo(win) -- restore window options
end
---@diagnostic disable-next-line: missing-fields