mirror of
https://github.com/neovim/neovim
synced 2025-07-29 18:01:55 +00:00
fix(api): make win_set_config with "win" for splits need "split/vertical"
Problem: currently, for splits, nvim_win_set_config accepts win without any of split or vertical set, which has little effect and seems error-prone. Solution: require at least one of split or vertical to also be set for splits. Also, update nvim_win_set_config docs, as it's no longer limited to just floating and external windows.
This commit is contained in:
@ -3291,11 +3291,11 @@ nvim_win_get_config({window}) *nvim_win_get_config()*
|
|||||||
Map defining the window configuration, see |nvim_open_win()|
|
Map defining the window configuration, see |nvim_open_win()|
|
||||||
|
|
||||||
nvim_win_set_config({window}, {config}) *nvim_win_set_config()*
|
nvim_win_set_config({window}, {config}) *nvim_win_set_config()*
|
||||||
Configures window layout. Currently only for floating and external windows
|
Configures window layout. Cannot be used to move the last window in a
|
||||||
(including changing a split window to those layouts).
|
tabpage to a different one.
|
||||||
|
|
||||||
When reconfiguring a floating window, absent option keys will not be
|
When reconfiguring a window, absent option keys will not be changed.
|
||||||
changed. `row`/`col` and `relative` must be reconfigured together.
|
`row`/`col` and `relative` must be reconfigured together.
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {window} Window handle, or 0 for current window
|
• {window} Window handle, or 0 for current window
|
||||||
|
8
runtime/lua/vim/_meta/api.lua
generated
8
runtime/lua/vim/_meta/api.lua
generated
@ -2207,11 +2207,11 @@ function vim.api.nvim_win_remove_ns(window, ns_id) end
|
|||||||
--- @param buffer integer Buffer handle
|
--- @param buffer integer Buffer handle
|
||||||
function vim.api.nvim_win_set_buf(window, buffer) end
|
function vim.api.nvim_win_set_buf(window, buffer) end
|
||||||
|
|
||||||
--- Configures window layout. Currently only for floating and external windows
|
--- Configures window layout. Cannot be used to move the last window in a
|
||||||
--- (including changing a split window to those layouts).
|
--- tabpage to a different one.
|
||||||
---
|
---
|
||||||
--- When reconfiguring a floating window, absent option keys will not be
|
--- When reconfiguring a window, absent option keys will not be changed.
|
||||||
--- changed. `row`/`col` and `relative` must be reconfigured together.
|
--- `row`/`col` and `relative` must be reconfigured together.
|
||||||
---
|
---
|
||||||
--- @param window integer Window handle, or 0 for current window
|
--- @param window integer Window handle, or 0 for current window
|
||||||
--- @param config vim.api.keyset.win_config Map defining the window configuration, see `nvim_open_win()`
|
--- @param config vim.api.keyset.win_config Map defining the window configuration, see `nvim_open_win()`
|
||||||
|
@ -361,11 +361,11 @@ static int win_split_flags(WinSplit split, bool toplevel)
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configures window layout. Currently only for floating and external windows
|
/// Configures window layout. Cannot be used to move the last window in a
|
||||||
/// (including changing a split window to those layouts).
|
/// tabpage to a different one.
|
||||||
///
|
///
|
||||||
/// When reconfiguring a floating window, absent option keys will not be
|
/// When reconfiguring a window, absent option keys will not be changed.
|
||||||
/// changed. `row`/`col` and `relative` must be reconfigured together.
|
/// `row`/`col` and `relative` must be reconfigured together.
|
||||||
///
|
///
|
||||||
/// @see |nvim_open_win()|
|
/// @see |nvim_open_win()|
|
||||||
///
|
///
|
||||||
@ -1099,11 +1099,15 @@ static bool parse_float_config(Dict(win_config) *config, WinConfig *fconfig, boo
|
|||||||
fconfig->window = config->win;
|
fconfig->window = config->win;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (has_relative) {
|
} else if (HAS_KEY_X(config, win)) {
|
||||||
if (HAS_KEY_X(config, win)) {
|
if (has_relative) {
|
||||||
api_set_error(err, kErrorTypeValidation,
|
api_set_error(err, kErrorTypeValidation,
|
||||||
"'win' key is only valid with relative='win' and relative=''");
|
"'win' key is only valid with relative='win' and relative=''");
|
||||||
return false;
|
return false;
|
||||||
|
} else if (!is_split) {
|
||||||
|
api_set_error(err, kErrorTypeValidation,
|
||||||
|
"non-float with 'win' requires at least 'split' or 'vertical'");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1727,6 +1727,15 @@ describe('API/win', function()
|
|||||||
config = api.nvim_win_get_config(win)
|
config = api.nvim_win_get_config(win)
|
||||||
eq('', config.relative)
|
eq('', config.relative)
|
||||||
eq('below', config.split)
|
eq('below', config.split)
|
||||||
|
|
||||||
|
eq(
|
||||||
|
"non-float with 'win' requires at least 'split' or 'vertical'",
|
||||||
|
pcall_err(api.nvim_win_set_config, 0, { win = 0 })
|
||||||
|
)
|
||||||
|
eq(
|
||||||
|
"non-float with 'win' requires at least 'split' or 'vertical'",
|
||||||
|
pcall_err(api.nvim_win_set_config, 0, { win = 0, relative = '' })
|
||||||
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('creates top-level splits', function()
|
it('creates top-level splits', function()
|
||||||
|
Reference in New Issue
Block a user