mirror of
https://github.com/neovim/neovim.git
synced 2026-04-20 14:25:32 +00:00
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:
@@ -392,6 +392,25 @@ static bool win_config_split(win_T *win, Dict(win_config) *config, WinConfig *fc
|
|||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
#define HAS_KEY_X(d, key) HAS_KEY(d, win_config, key)
|
#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;
|
win_T *parent = NULL;
|
||||||
tabpage_T *parent_tp = NULL;
|
tabpage_T *parent_tp = NULL;
|
||||||
if (config->win == 0) {
|
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)) {
|
if (!check_split_disallowed_err(win, err)) {
|
||||||
return false; // error already set
|
return false; // error already set
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3524,6 +3524,21 @@ describe('API/win', function()
|
|||||||
'Cannot split a floating window',
|
'Cannot split a floating window',
|
||||||
pcall_err(api.nvim_win_set_config, win, { win = 0, split = 'right' })
|
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)
|
end)
|
||||||
|
|
||||||
it('cannot move autocmd window between tabpages', function()
|
it('cannot move autocmd window between tabpages', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user