From 6ae6cf5d61979e2f04dda14ba249ecbe21999faf Mon Sep 17 00:00:00 2001 From: "neovim-backports[bot]" <175700243+neovim-backports[bot]@users.noreply.github.com> Date: Wed, 22 Apr 2026 08:18:03 -0400 Subject: [PATCH] fix(float): don't unload 'hidden' float buffer with :close! (#39304) Problem: When closing floating windows to close a tabpage, if the current buffer will unload, buffers contained in those floating windows will too (unexpectedly). Solution: Don't pass along "free_buf" argument; check 'bufhidden' for the buffer in the to be closed float. (cherry picked from commit 5b0ad4a0607498616b984c63ae1a6903cb835c66) Co-authored-by: luukvbaal --- src/nvim/window.c | 4 ++-- test/functional/ui/float_spec.lua | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/nvim/window.c b/src/nvim/window.c index f512057d79..75e556e4a2 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2853,7 +2853,7 @@ int win_close(win_T *win, bool free_buf, bool force) // close the last window until the there are no floating windows while (lastwin->w_floating) { // `force` flag isn't actually used when closing a floating window. - if (win_close(lastwin, free_buf, true) == FAIL) { + if (win_close(lastwin, !buf_hide(lastwin->w_buffer), true) == FAIL) { // If closing the window fails give up, to avoid looping forever. return FAIL; } @@ -3216,7 +3216,7 @@ bool win_close_othertab(win_T *win, int free_buf, tabpage_T *tp, bool force) // close the last window until the there are no floating windows while (tp->tp_lastwin->w_floating) { // `force` flag isn't actually used when closing a floating window. - if (!win_close_othertab(tp->tp_lastwin, free_buf, tp, true)) { + if (!win_close_othertab(tp->tp_lastwin, !buf_hide(tp->tp_lastwin->w_buffer), tp, true)) { // If closing the window fails give up, to avoid looping forever. goto leave_open; } diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index e5bf766000..1d467d17ec 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -1072,6 +1072,15 @@ describe('float window', function() command('close') assert_alive() end) + + it('does not unload bufhidden=hide buffer', function() + local buf = api.nvim_create_buf(false, true) + command('set nohidden') + api.nvim_open_tabpage(0, true, {}) + api.nvim_open_win(buf, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0 }) + command('close!') + eq(true, api.nvim_buf_is_loaded(buf)) + end) end) it('placed relative to tabline and laststatus', function()