diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-03-10 08:37:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-10 08:37:16 +0800 |
commit | 9bd4a2807960ea3e82b0454861b399f4ac6d8a92 (patch) | |
tree | 68fd7c2f008a70c449a5c130a9b98d44de407fe6 /src | |
parent | 731e7f51ee40778b5baeec99aaf1d551b0855667 (diff) | |
download | rneovim-9bd4a2807960ea3e82b0454861b399f4ac6d8a92.tar.gz rneovim-9bd4a2807960ea3e82b0454861b399f4ac6d8a92.tar.bz2 rneovim-9bd4a2807960ea3e82b0454861b399f4ac6d8a92.zip |
fix(window): :close crash if WinClosed from float closes window (#27794)
Problem: :close crash if WinClosed from float closes window.
Solution: Check if window has already been closed.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/window.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c index c0a9b1e39b..a76953d900 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2560,6 +2560,7 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf, bool force, tab emsg(_("E814: Cannot close window, only autocmd window would remain")); return true; } + if (force || can_close_floating_windows()) { // close the last window until the there are no floating windows while (lastwin->w_floating) { @@ -2573,6 +2574,10 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf, bool force, tab emsg(e_floatonly); return true; } + + if (!win_valid_any_tab(win)) { + return true; // window already closed by autocommands + } } buf_T *old_curbuf = curbuf; @@ -2591,10 +2596,6 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf, bool force, tab // that below. goto_tabpage_tp(alt_tabpage(), false, true); - // save index for tabclosed event - char prev_idx[NUMBUFLEN]; - snprintf(prev_idx, NUMBUFLEN, "%i", tabpage_index(prev_curtab)); - // Safety check: Autocommands may have closed the window when jumping // to the other tab page. if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win) { |