From 440485f86c41ece0f2af2a0fc74a557380fdfec3 Mon Sep 17 00:00:00 2001 From: hat0uma <55551571+hat0uma@users.noreply.github.com> Date: Sun, 7 Dec 2025 19:04:37 +0900 Subject: [PATCH] fix(sticky_header): use vim.schedule for window close during BufUnload --- lua/csvview/sticky_header.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lua/csvview/sticky_header.lua b/lua/csvview/sticky_header.lua index ee388e4..0b1226c 100644 --- a/lua/csvview/sticky_header.lua +++ b/lua/csvview/sticky_header.lua @@ -214,11 +214,17 @@ function M.close_header_win_for(winid) return end - -- Close - if vim.api.nvim_win_is_valid(header_win) then - pcall(vim.api.nvim_win_close, header_win, true) - end M._sticky_header_wins[winid] = nil + if not vim.api.nvim_win_is_valid(header_win) then + return + end + + -- Close (use vim.schedule to avoid issues when called during BufUnload) + vim.schedule(function() + if vim.api.nvim_win_is_valid(header_win) then + pcall(vim.api.nvim_win_close, header_win, true) + end + end) end --- statuscolumn function for sticky header window.