diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/buffer.c | 16 | ||||
-rw-r--r-- | src/nvim/window.c | 6 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 1fe80dc24c..7fc880fb41 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1043,8 +1043,20 @@ static int empty_curbuf(int close_others, int forceit, int action) if (close_others) { if (curwin->w_floating) { - // Last window must be non-floating. - curwin = firstwin; + bool can_close_all_others = false; + for (win_T *wp = firstwin; !wp->w_floating; wp = wp->w_next) { + if (wp->w_buffer != curbuf) { + // Found another non-floating window with a different (probably unlisted) buffer. + // Closing all other windows with the this buffer is fine in this case. + can_close_all_others = true; + break; + } + } + if (!can_close_all_others) { + // Closing all other windows with this buffer will close all non-floating windows. + // Move to a non-floating window then. + curwin = firstwin; + } } // Close any other windows on this buffer, then make it empty. close_windows(buf, true); diff --git a/src/nvim/window.c b/src/nvim/window.c index bcc7a92b33..fb7878c2f4 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2350,9 +2350,9 @@ void entering_window(win_T *const win) } } -/// Closes all windows for buffer `buf` until there is only one non-floating window. +/// Closes all windows for buffer `buf` unless there is only one non-floating window. /// -/// @param keep_curwin don't close `curwin`, but caller must ensure `curwin` is non-floating. +/// @param keep_curwin don't close `curwin` void close_windows(buf_T *buf, bool keep_curwin) { tabpage_T *tp, *nexttp; @@ -2360,8 +2360,6 @@ void close_windows(buf_T *buf, bool keep_curwin) ++RedrawingDisabled; - assert(!keep_curwin || !curwin->w_floating); - // Start from lastwin to close floating windows with the same buffer first. // When the autocommand window is involved win_close() may need to print an error message. for (win_T *wp = lastwin; wp != NULL && (lastwin == aucmd_win || !one_window(wp));) { |