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()