fix(api): ignore split_disallowed when opening a float

Problem: split_disallowed seemingly exists to prevent issues from changing
frames to accomodate a split window, which doesn't apply to floats.

Solution: remove the restriction for nvim_open_win, but only for floats.
(continue to check b_locked_split though)

NOTE: like before, the buffer we check b_locked_split for may not actually be
the target buffer "buf", as the later call to win_set_buf can fail to switch to
"buf" due to autocommands. (among other things)

Maybe we could attempt to close the new window in that case (or switch to a
different buffer if that also fails), but this is safer. (and simpler)

Fixes #36857 (and possibly some spurious E242s I've observed from extui)
This commit is contained in:
Sean Dewar
2025-12-17 16:38:52 +00:00
parent 756e1eb017
commit d788864cde
2 changed files with 16 additions and 5 deletions

View File

@@ -2000,6 +2000,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(
@@ -2033,10 +2040,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()'))
@@ -2052,7 +2059,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)