diff --git a/lua/snacks/scroll.lua b/lua/snacks/scroll.lua index 4c8d07c1..59b2dc0d 100644 --- a/lua/snacks/scroll.lua +++ b/lua/snacks/scroll.lua @@ -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