diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2023-07-24 14:19:01 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2023-07-26 20:44:46 +0100 |
commit | 472271199e483d3f23d62c272b20c5290eec5474 (patch) | |
tree | 9965e5a35f07a77365d48148c251a52afd2b4d8c /src/nvim/window.c | |
parent | 5d921e28c1cc33eced22bbfa823460ca241e3dc1 (diff) | |
download | rneovim-472271199e483d3f23d62c272b20c5290eec5474.tar.gz rneovim-472271199e483d3f23d62c272b20c5290eec5474.tar.bz2 rneovim-472271199e483d3f23d62c272b20c5290eec5474.zip |
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.
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r-- | src/nvim/window.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c index fa7ca53b08..d55bda18c8 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2670,6 +2670,23 @@ static bool can_close_floating_windows(void) return true; } +/// @return true if, considering the cmdwin, `win` is safe to close. +/// If false and `win` is the cmdwin, it is closed; otherwise, `err` is set. +bool can_close_in_cmdwin(win_T *win, Error *err) + FUNC_ATTR_NONNULL_ALL +{ + if (cmdwin_type != 0) { + if (win == curwin) { + cmdwin_result = Ctrl_C; + return false; + } else if (win == cmdwin_old_curwin) { + api_set_error(err, kErrorTypeException, "%s", e_cmdwin); + return false; + } + } + return true; +} + /// Close the possibly last window in a tab page. /// /// @param win window to close |