feat(api): allow win_hide to close cmdwin or non-previous windows

This aligns its behaviour better with `nvim_win_close`.

Note that `:hide` is actually incapable of closing the cmdwin, unlike `:close`
and `:quit`, so this is a bit of a difference in behaviour.
This commit is contained in:
Sean Dewar
2023-07-24 14:19:01 +01:00
parent 5d921e28c1
commit 472271199e
5 changed files with 41 additions and 15 deletions

View File

@@ -362,10 +362,10 @@ Boolean nvim_win_is_valid(Window window)
/// @param[out] err Error details, if any
void nvim_win_hide(Window window, Error *err)
FUNC_API_SINCE(7)
FUNC_API_TEXTLOCK
FUNC_API_TEXTLOCK_ALLOW_CMDWIN
{
win_T *win = find_window_by_handle(window, err);
if (!win) {
if (!win || !can_close_in_cmdwin(win, err)) {
return;
}
@@ -397,20 +397,10 @@ void nvim_win_close(Window window, Boolean force, Error *err)
FUNC_API_TEXTLOCK_ALLOW_CMDWIN
{
win_T *win = find_window_by_handle(window, err);
if (!win) {
if (!win || !can_close_in_cmdwin(win, err)) {
return;
}
if (cmdwin_type != 0) {
if (win == curwin) {
cmdwin_result = Ctrl_C;
return;
} else if (win == cmdwin_old_curwin) {
api_set_error(err, kErrorTypeException, "%s", e_cmdwin);
return;
}
}
tabpage_T *tabpage = win_find_tabpage(win);
TryState tstate;
try_enter(&tstate);