diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 6a7baaab46..b7a00adbc8 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -290,8 +290,12 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err } } } else { - if (!check_split_disallowed_err(curwin, err)) { - goto cleanup; // error already set + // Unlike check_split_disallowed_err, ignore `split_disallowed`, as opening a float shouldn't + // mess with the frame structure. Still check `b_locked_split` to avoid opening more windows + // into a closing buffer, though. + if (curwin->w_buffer->b_locked_split) { // Can't instead check `buf` in case win_set_buf fails! + api_set_error(err, kErrorTypeException, "E1159: Cannot open a float when closing the buffer"); + goto cleanup; } wp = win_new_float(NULL, false, fconfig, err); } diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 03df326781..7ec2288e21 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -1777,6 +1777,13 @@ describe('API/win', function() it('checks if splitting disallowed', function() command('split | autocmd WinEnter * ++once call nvim_open_win(0, 0, #{split: "right"})') matches("E242: Can't split a window while closing another$", pcall_err(command, 'quit')) + -- E242 is not needed for floats. + exec([[ + split + autocmd WinEnter * ++once let g:win = nvim_open_win(0, 0, #{relative: "editor", row: 0, col: 0, width: 5, height: 5}) + quit + ]]) + eq('editor', eval('nvim_win_get_config(g:win).relative')) command('only | autocmd BufHidden * ++once call nvim_open_win(0, 0, #{split: "left"})') matches( @@ -1810,10 +1817,10 @@ describe('API/win', function() only new let g:buf = bufnr() - autocmd BufUnload * ++once let g:win = nvim_open_win(g:buf, 0, #{relative: "editor", width: 5, height: 5, row: 1, col: 1}) + autocmd BufUnload * ++once call nvim_open_win(g:buf, 0, #{relative: "editor", width: 5, height: 5, row: 1, col: 1}) setlocal bufhidden=unload ]]) - matches('E1159: Cannot split a window when closing the buffer$', pcall_err(command, 'quit')) + matches('E1159: Cannot open a float when closing the buffer$', pcall_err(command, 'quit')) eq(false, eval('nvim_buf_is_loaded(g:buf)')) eq(0, eval('win_findbuf(g:buf)->len()')) @@ -1829,7 +1836,7 @@ describe('API/win', function() \| call nvim_open_win(g:buf2, 1, #{relative: 'editor', width: 5, height: 5, col: 5, row: 5}) setlocal bufhidden=wipe ]]) - matches('E1159: Cannot split a window when closing the buffer$', pcall_err(command, 'quit')) + matches('E1159: Cannot open a float when closing the buffer$', pcall_err(command, 'quit')) eq(false, eval('nvim_buf_is_loaded(g:buf)')) eq(0, eval('win_findbuf(g:buf)->len()')) -- BufLeave shouldn't run here (buf2 isn't deleted and remains hidden)