fix(api): win_set_config error message for splitting from a float #35650

Problem: after #34287 nvim_win_set_config no longer errors when attempting to
split from a floating window only if "win" is 0.

Solution: fix the regression, reduce the scope of "parent" and similar checks to
only where it's currently used and add test coverage for the errors.
This commit is contained in:
Sean Dewar
2025-09-06 21:22:46 +01:00
committed by GitHub
parent 14e94f4617
commit da39966a3a
2 changed files with 81 additions and 24 deletions

View File

@@ -3325,5 +3325,58 @@ describe('API/win', function()
eq({ { 'OLD_FOOTER' } }, api.nvim_win_get_config(win).footer)
end)
end)
it('cannot split from a float', function()
local win = api.nvim_get_current_win()
local float_win = api.nvim_open_win(0, true, {
relative = 'editor',
width = 10,
height = 10,
row = 10,
col = 10,
})
eq(
'Cannot split a floating window',
pcall_err(api.nvim_win_set_config, win, { win = float_win, split = 'right' })
)
eq(
'Cannot split a floating window',
pcall_err(api.nvim_win_set_config, win, { win = 0, split = 'right' })
)
end)
it('cannot move autocmd window between tabpages', function()
local win_type, split_ok, err = exec_lua(function()
local other_tp_win = vim.api.nvim_get_current_win()
vim.cmd.tabnew()
local win_type, split_ok, err
vim.api.nvim_buf_call(vim.api.nvim_create_buf(true, true), function()
win_type = vim.fn.win_gettype()
split_ok, err =
pcall(vim.api.nvim_win_set_config, 0, { win = other_tp_win, split = 'right' })
end)
return win_type, split_ok, err
end)
eq('autocmd', win_type)
eq({ false, 'Cannot move autocmd window to another tabpage' }, { split_ok, err })
end)
it('cannot move cmdwin between tabpages', function()
local other_tp_win = api.nvim_get_current_win()
command('tabnew')
local old_curwin = api.nvim_get_current_win()
feed('q:')
eq('command', fn.win_gettype())
eq(
'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
pcall_err(api.nvim_win_set_config, 0, { win = other_tp_win, split = 'right' })
)
-- Shouldn't move the old curwin from before we entered the cmdwin either.
eq(
'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
pcall_err(api.nvim_win_set_config, old_curwin, { win = other_tp_win, split = 'right' })
)
end)
end)
end)