fix(aucmd_win): always make aucmd_win the last window

This commit is contained in:
zeertzjq 2022-03-21 21:19:09 +08:00
parent 7735163652
commit 89712dcbf8
3 changed files with 32 additions and 11 deletions

View File

@ -150,7 +150,7 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(float_config) *config, E
if (!parse_float_config(config, &fconfig, false, true, err)) { if (!parse_float_config(config, &fconfig, false, true, err)) {
return 0; return 0;
} }
win_T *wp = win_new_float(NULL, fconfig, err); win_T *wp = win_new_float(NULL, false, fconfig, err);
if (!wp) { if (!wp) {
return 0; return 0;
} }
@ -200,7 +200,7 @@ void nvim_win_set_config(Window window, Dict(float_config) *config, Error *err)
return; return;
} }
if (new_float) { if (new_float) {
if (!win_new_float(win, fconfig, err)) { if (!win_new_float(win, false, fconfig, err)) {
return; return;
} }
redraw_later(win, NOT_VALID); redraw_later(win, NOT_VALID);

View File

@ -560,7 +560,7 @@ wingotofile:
config.height = curwin->w_height; config.height = curwin->w_height;
config.external = true; config.external = true;
Error err = ERROR_INIT; Error err = ERROR_INIT;
if (!win_new_float(curwin, config, &err)) { if (!win_new_float(curwin, false, config, &err)) {
emsg(err.msg); emsg(err.msg);
api_clear_error(&err); api_clear_error(&err);
beep_flush(); beep_flush();
@ -629,16 +629,18 @@ void win_set_buf(Window window, Buffer buffer, bool noautocmd, Error *err)
/// Create a new float. /// Create a new float.
/// ///
/// if wp == NULL allocate a new window, otherwise turn existing window into a /// @param wp if NULL, allocate a new window, otherwise turn existing window into a float.
/// float. It must then already belong to the current tabpage! /// It must then already belong to the current tabpage!
/// /// @param last make the window the last one in the window list.
/// config must already have been validated! /// Only used when allocating the autocommand window.
win_T *win_new_float(win_T *wp, FloatConfig fconfig, Error *err) /// @param config must already have been validated!
win_T *win_new_float(win_T *wp, bool last, FloatConfig fconfig, Error *err)
{ {
if (wp == NULL) { if (wp == NULL) {
wp = win_alloc(lastwin_nofloating(), false); wp = win_alloc(last ? lastwin : lastwin_nofloating(), false);
win_init(wp, curwin, 0); win_init(wp, curwin, 0);
} else { } else {
assert(!last);
assert(!wp->w_floating); assert(!wp->w_floating);
if (firstwin == wp && lastwin_nofloating() == wp) { if (firstwin == wp && lastwin_nofloating() == wp) {
// last non-float // last non-float
@ -2543,7 +2545,7 @@ int win_close(win_T *win, bool free_buf, bool force)
emsg(_(e_autocmd_close)); emsg(_(e_autocmd_close));
return FAIL; return FAIL;
} }
if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window()) { if (lastwin == aucmd_win && one_window()) {
emsg(_("E814: Cannot close window, only autocmd window would remain")); emsg(_("E814: Cannot close window, only autocmd window would remain"));
return FAIL; return FAIL;
} }
@ -3844,7 +3846,7 @@ void win_alloc_aucmd_win(void)
fconfig.width = Columns; fconfig.width = Columns;
fconfig.height = 5; fconfig.height = 5;
fconfig.focusable = false; fconfig.focusable = false;
aucmd_win = win_new_float(NULL, fconfig, &err); aucmd_win = win_new_float(NULL, true, fconfig, &err);
aucmd_win->w_buffer->b_nwindows--; aucmd_win->w_buffer->b_nwindows--;
RESET_BINDING(aucmd_win); RESET_BINDING(aucmd_win);
} }

View File

@ -398,6 +398,25 @@ describe('autocmd', function()
]]) ]])
end) end)
describe('closing last non-floating window in tab from `aucmd_win`', function()
before_each(function()
command('edit Xa.txt')
command('tabnew Xb.txt')
command('autocmd BufAdd Xa.txt 1close')
end)
it('gives E814 when there are no other floating windows', function()
eq('Vim(close):E814: Cannot close window, only autocmd window would remain',
pcall_err(command, 'doautoall BufAdd'))
end)
it('gives E814 when there are other floating windows', function()
meths.open_win(0, true, {width = 10, height = 10, relative = 'editor', row = 10, col = 10})
eq('Vim(close):E814: Cannot close window, only autocmd window would remain',
pcall_err(command, 'doautoall BufAdd'))
end)
end)
it(':doautocmd does not warn "No matching autocommands" #10689', function() it(':doautocmd does not warn "No matching autocommands" #10689', function()
local screen = Screen.new(32, 3) local screen = Screen.new(32, 3)
screen:attach() screen:attach()