mirror of
https://github.com/neovim/neovim.git
synced 2026-02-21 18:01:17 +10:00
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:
@@ -290,8 +290,12 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!check_split_disallowed_err(curwin, err)) {
|
// Unlike check_split_disallowed_err, ignore `split_disallowed`, as opening a float shouldn't
|
||||||
goto cleanup; // error already set
|
// 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);
|
wp = win_new_float(NULL, false, fconfig, err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1777,6 +1777,13 @@ describe('API/win', function()
|
|||||||
it('checks if splitting disallowed', function()
|
it('checks if splitting disallowed', function()
|
||||||
command('split | autocmd WinEnter * ++once call nvim_open_win(0, 0, #{split: "right"})')
|
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'))
|
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"})')
|
command('only | autocmd BufHidden * ++once call nvim_open_win(0, 0, #{split: "left"})')
|
||||||
matches(
|
matches(
|
||||||
@@ -1810,10 +1817,10 @@ describe('API/win', function()
|
|||||||
only
|
only
|
||||||
new
|
new
|
||||||
let g:buf = bufnr()
|
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
|
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(false, eval('nvim_buf_is_loaded(g:buf)'))
|
||||||
eq(0, eval('win_findbuf(g:buf)->len()'))
|
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})
|
\| call nvim_open_win(g:buf2, 1, #{relative: 'editor', width: 5, height: 5, col: 5, row: 5})
|
||||||
setlocal bufhidden=wipe
|
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(false, eval('nvim_buf_is_loaded(g:buf)'))
|
||||||
eq(0, eval('win_findbuf(g:buf)->len()'))
|
eq(0, eval('win_findbuf(g:buf)->len()'))
|
||||||
-- BufLeave shouldn't run here (buf2 isn't deleted and remains hidden)
|
-- BufLeave shouldn't run here (buf2 isn't deleted and remains hidden)
|
||||||
|
|||||||
Reference in New Issue
Block a user