From 539b8027a3099399ad362896dc7de0e93e2f5bfa Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Sat, 14 Feb 2026 15:26:36 +0200 Subject: [PATCH] fix(pack): explicitly close confirmation window #37861 Problem: Executing `nvim_buf_delete()` does not guarantee that the window which shows the buffer is going to close after `:write` or `:quit`. In particular, if there is no listed buffer present. Solution: Explicitly close the window that was created for confirmation buffer. Use `pcall` to catch cases when the window was already closed or when it is the last window. --- runtime/lua/vim/pack.lua | 1 + test/functional/plugin/pack_spec.lua | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua index 3371f66c31..f336a22c7a 100644 --- a/runtime/lua/vim/pack.lua +++ b/runtime/lua/vim/pack.lua @@ -1122,6 +1122,7 @@ local function show_confirm_buf(lines, on_finish) local win_id = api.nvim_get_current_win() local delete_buffer = vim.schedule_wrap(function() + pcall(api.nvim_win_close, win_id, true) pcall(api.nvim_buf_delete, bufnr, { force = true }) vim.cmd.redraw() end) diff --git a/test/functional/plugin/pack_spec.lua b/test/functional/plugin/pack_spec.lua index d062a53b76..c63769b82f 100644 --- a/test/functional/plugin/pack_spec.lua +++ b/test/functional/plugin/pack_spec.lua @@ -1397,6 +1397,16 @@ describe('vim.pack', function() n.exec('tabonly') n.exec('write') eq('', n.eval('v:errmsg')) + + -- Should cleanly close tabpage even if there are only scratch buffers + n.exec('%bwipeout') + local init_buf = api.nvim_get_current_buf() + api.nvim_set_current_buf(api.nvim_create_buf(false, true)) + api.nvim_buf_delete(init_buf, { force = true }) + exec_lua('vim.pack.update()') + n.exec('write') + eq(1, #api.nvim_list_tabpages()) + eq(1, #api.nvim_list_bufs()) end) it('has in-process LSP features', function()