From 6fc53b8a1114a03c9906eee3a373a8b07cf4a4b6 Mon Sep 17 00:00:00 2001 From: Booyaka101 Date: Sun, 7 Jun 2026 11:30:31 +0800 Subject: [PATCH] fix(dashboard): guard cursor update when window shows another buffer When the dashboard window's buffer is replaced (e.g. `:enew`) while another split still shows the dashboard, the `CursorMoved` autocmd kept positioning the cursor in `self.win`, which now displays a shorter buffer, raising "Invalid cursor line: out of range". Skip when the window is invalid or no longer shows the dashboard buffer. Fixes #2869 --- lua/snacks/dashboard.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/snacks/dashboard.lua b/lua/snacks/dashboard.lua index 404778059..460d86cda 100644 --- a/lua/snacks/dashboard.lua +++ b/lua/snacks/dashboard.lua @@ -718,6 +718,11 @@ function D:update() -- cursor movement local last = { 1, 0 } local function update_cursor() + -- the dashboard window may now show a different buffer (e.g. it was replaced + -- with `:enew` while another split still displays the dashboard) + if not vim.api.nvim_win_is_valid(self.win) or vim.api.nvim_win_get_buf(self.win) ~= self.buf then + return + end local item = self:find(vim.api.nvim_win_get_cursor(self.win), last) -- can happen for panes without actionable items item = item or vim.tbl_filter(function(it)