fix(api): unnecessary errors when not moving split

Problem: nvim_win_set_config may raise unnecessary errors when not moving a
split.

Solution: skip checks related to moving when only maybe resizing a split.
This commit is contained in:
Sean Dewar
2026-03-09 00:31:04 +00:00
parent e13e850517
commit 0ee8323f2b
2 changed files with 34 additions and 19 deletions

View File

@@ -392,6 +392,25 @@ static bool win_config_split(win_T *win, Dict(win_config) *config, WinConfig *fc
FUNC_ATTR_NONNULL_ALL
{
#define HAS_KEY_X(d, key) HAS_KEY(d, win_config, key)
bool was_split = !win->w_floating;
bool has_split = HAS_KEY_X(config, split);
bool has_vertical = HAS_KEY_X(config, vertical);
WinSplit old_split = win_split_dir(win);
if (has_vertical && !has_split) {
if (config->vertical) {
fconfig->split = (old_split == kWinSplitRight || p_spr) ? kWinSplitRight : kWinSplitLeft;
} else {
fconfig->split = (old_split == kWinSplitBelow || p_sb) ? kWinSplitBelow : kWinSplitAbove;
}
}
// If there's no "vertical" or "split" set, or if "split" is unchanged, then we can just change
// the size of the window.
if ((!has_vertical && !has_split)
|| (was_split && !HAS_KEY_X(config, win) && old_split == fconfig->split)) {
goto resize;
}
win_T *parent = NULL;
tabpage_T *parent_tp = NULL;
if (config->win == 0) {
@@ -422,25 +441,6 @@ static bool win_config_split(win_T *win, Dict(win_config) *config, WinConfig *fc
}
}
bool was_split = !win->w_floating;
bool has_split = HAS_KEY_X(config, split);
bool has_vertical = HAS_KEY_X(config, vertical);
WinSplit old_split = win_split_dir(win);
if (has_vertical && !has_split) {
if (config->vertical) {
fconfig->split = (old_split == kWinSplitRight || p_spr) ? kWinSplitRight : kWinSplitLeft;
} else {
fconfig->split = (old_split == kWinSplitBelow || p_sb) ? kWinSplitBelow : kWinSplitAbove;
}
}
// If there's no "vertical" or "split" set, or if "split" is unchanged, then we can just change
// the size of the window.
if ((!has_vertical && !has_split)
|| (was_split && !HAS_KEY_X(config, win) && old_split == fconfig->split)) {
goto resize;
}
if (!check_split_disallowed_err(win, err)) {
return false; // error already set
}

View File

@@ -3524,6 +3524,21 @@ describe('API/win', function()
'Cannot split a floating window',
pcall_err(api.nvim_win_set_config, win, { win = 0, split = 'right' })
)
-- No errors when not actually splitting.
local cfg = api.nvim_win_get_config(win)
api.nvim_win_set_config(win, {})
eq(cfg, api.nvim_win_get_config(win))
eq(1, eval('&cmdheight'))
api.nvim_win_set_config(win, { height = 1 })
cfg.height = 1
eq(cfg, api.nvim_win_get_config(win))
eq(23, eval('&cmdheight'))
api.nvim_win_set_config(win, { style = 'minimal' })
cfg.style = 'minimal'
eq(cfg, api.nvim_win_get_config(win))
end)
it('cannot move autocmd window between tabpages', function()