From c0a29931e29bbb40650df01918826cdb64e8fc32 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 23 Sep 2023 14:42:59 +0800 Subject: [PATCH] fix(unhide): close floating windows first (#25318) --- src/nvim/buffer.c | 9 ++++++--- test/functional/ui/float_spec.lua | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 0564b4305b..f2174e055b 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3616,8 +3616,11 @@ void ex_buffer_all(exarg_T *eap) } while (true) { tpnext = curtab->tp_next; - for (wp = firstwin; wp != NULL; wp = wpnext) { - wpnext = wp->w_next; + // Try to close floating windows first + for (wp = lastwin->w_floating ? lastwin : firstwin; wp != NULL; wp = wpnext) { + wpnext = wp->w_floating + ? wp->w_prev->w_floating ? wp->w_prev : firstwin + : (wp->w_next == NULL || wp->w_next->w_floating) ? NULL : wp->w_next; if ((wp->w_buffer->b_nwindows > 1 || ((cmdmod.cmod_split & WSP_VERT) ? wp->w_height + wp->w_hsep_height + wp->w_status_height < Rows - p_ch @@ -3632,7 +3635,7 @@ void ex_buffer_all(exarg_T *eap) } // Just in case an autocommand does something strange with // windows: start all over... - wpnext = firstwin; + wpnext = lastwin->w_floating ? lastwin : firstwin; tpnext = first_tabpage; open_wins = 0; } else { diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 93ca1aef3f..e21e4e4aad 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -522,6 +522,16 @@ describe('float window', function() eq(5, meths.get_option_value('scroll', {win=float_win.id})) end) + it(':unhide works when there are floating windows #17797', function() + local float_opts = {relative = 'editor', row = 1, col = 1, width = 10, height = 10} + local w0 = curwin() + meths.open_win(0, false, float_opts) + meths.open_win(0, false, float_opts) + eq(3, #meths.list_wins()) + command('unhide') + eq({ w0 }, meths.list_wins()) + end) + describe('with only one tabpage,', function() local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1} local old_buf, old_win