mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 16:28:17 +00:00
This reverts commit 0371d0f7af
.
> 'bufhidden' option exists. I don't think we should assume autoclosing
windows are fine just because 'hidden' is set.
This commit is contained in:
@@ -368,7 +368,7 @@ newwindow:
|
||||
newtab = curtab;
|
||||
goto_tabpage_tp(oldtab, true, true);
|
||||
if (curwin == wp) {
|
||||
win_close(curwin, false);
|
||||
win_close(curwin, false, false);
|
||||
}
|
||||
if (valid_tabpage(newtab)) {
|
||||
goto_tabpage_tp(newtab, true, true);
|
||||
@@ -517,7 +517,7 @@ wingotofile:
|
||||
RESET_BINDING(curwin);
|
||||
if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL, ECMD_HIDE, NULL) == FAIL) {
|
||||
// Failed to open the file, close the window opened for it.
|
||||
win_close(curwin, false);
|
||||
win_close(curwin, false, false);
|
||||
goto_tabpage_win(oldtab, oldwin);
|
||||
} else if (nchar == 'F' && lnum >= 0) {
|
||||
curwin->w_cursor.lnum = lnum;
|
||||
@@ -2491,7 +2491,7 @@ void close_windows(buf_T *buf, bool keep_curwin)
|
||||
for (win_T *wp = lastwin; wp != NULL && (is_aucmd_win(lastwin) || !one_window(wp));) {
|
||||
if (wp->w_buffer == buf && (!keep_curwin || wp != curwin)
|
||||
&& !(wp->w_closing || wp->w_buffer->b_locked > 0)) {
|
||||
if (win_close(wp, false) == FAIL) {
|
||||
if (win_close(wp, false, false) == FAIL) {
|
||||
// If closing the window fails give up, to avoid looping forever.
|
||||
break;
|
||||
}
|
||||
@@ -2567,6 +2567,24 @@ bool last_nonfloat(win_T *wp) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
return wp != NULL && firstwin == wp && !(wp->w_next && !wp->w_floating);
|
||||
}
|
||||
|
||||
/// Check if floating windows in the current tab can be closed.
|
||||
/// Do not call this when the autocommand window is in use!
|
||||
///
|
||||
/// @return true if all floating windows can be closed
|
||||
static bool can_close_floating_windows(void)
|
||||
{
|
||||
assert(!is_aucmd_win(lastwin));
|
||||
for (win_T *wp = lastwin; wp->w_floating; wp = wp->w_prev) {
|
||||
buf_T *buf = wp->w_buffer;
|
||||
int need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1);
|
||||
|
||||
if (need_hide && !buf_hide(buf)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Close the possibly last window in a tab page.
|
||||
///
|
||||
/// @param win window to close
|
||||
@@ -2658,7 +2676,7 @@ static void win_close_buffer(win_T *win, bool free_buf, bool abort_if_last)
|
||||
//
|
||||
// Called by :quit, :close, :xit, :wq and findtag().
|
||||
// Returns FAIL when the window was not closed.
|
||||
int win_close(win_T *win, bool free_buf)
|
||||
int win_close(win_T *win, bool free_buf, bool force)
|
||||
{
|
||||
tabpage_T *prev_curtab = curtab;
|
||||
frame_T *win_frame = win->w_floating ? NULL : win->w_frame->fr_parent;
|
||||
@@ -2682,14 +2700,18 @@ int win_close(win_T *win, bool free_buf)
|
||||
emsg(_("E814: Cannot close window, only autocmd window would remain"));
|
||||
return FAIL;
|
||||
}
|
||||
// close the last window until the there are no floating windows
|
||||
while (lastwin->w_floating) {
|
||||
buf_T *buf = lastwin->w_buffer;
|
||||
bool need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1);
|
||||
if (win_close(lastwin, !need_hide && !buf_hide(buf)) == FAIL) {
|
||||
// If closing the window fails give up, to avoid looping forever.
|
||||
return FAIL;
|
||||
if (force || can_close_floating_windows()) {
|
||||
// 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 closing the window fails give up, to avoid looping forever.
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
emsg(e_floatonly);
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3879,7 +3901,7 @@ void close_others(int message, int forceit)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
win_close(wp, !buf_hide(wp->w_buffer) && !bufIsChanged(wp->w_buffer));
|
||||
win_close(wp, !buf_hide(wp->w_buffer) && !bufIsChanged(wp->w_buffer), false);
|
||||
}
|
||||
|
||||
if (message && !ONE_WINDOW) {
|
||||
|
Reference in New Issue
Block a user