0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.3591: no event is triggered when closing a window

Problem:    No event is triggered when closing a window.
Solution:   Add the WinClosed event. (Naohiro Ono, closes #9110)
This commit is contained in:
naohiro ono
2021-11-13 12:38:49 +00:00
committed by Bram Moolenaar
parent a0fca17251
commit 23beefed73
6 changed files with 84 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ static void win_exchange(long);
static void win_rotate(int, int);
static void win_totop(int size, int flags);
static void win_equal_rec(win_T *next_curwin, int current, frame_T *topfr, int dir, int col, int row, int width, int height);
static void trigger_winclosed(win_T *win);
static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp);
static frame_T *win_altframe(win_T *win, tabpage_T *tp);
static tabpage_T *alt_tabpage(void);
@@ -2566,6 +2567,13 @@ win_close(win_T *win, int free_buf)
if (popup_win_closed(win) && !win_valid(win))
return FAIL;
#endif
// Trigger WinClosed just before starting to free window-related resources.
trigger_winclosed(win);
// autocmd may have freed the window already.
if (!win_valid_any_tab(win))
return OK;
win_close_buffer(win, free_buf ? DOBUF_UNLOAD : 0, TRUE);
if (only_one_window() && win_valid(win) && win->w_buffer == NULL
@@ -2710,6 +2718,20 @@ win_close(win_T *win, int free_buf)
return OK;
}
static void
trigger_winclosed(win_T *win)
{
static int recursive = FALSE;
char_u winid[NUMBUFLEN];
if (recursive)
return;
recursive = TRUE;
vim_snprintf((char *)winid, sizeof(winid), "%i", win->w_id);
apply_autocmds(EVENT_WINCLOSED, winid, winid, FALSE, win->w_buffer);
recursive = FALSE;
}
/*
* Close window "win" in tab page "tp", which is not the current tab page.
* This may be the last window in that tab page and result in closing the tab,
@@ -2731,6 +2753,12 @@ win_close_othertab(win_T *win, int free_buf, tabpage_T *tp)
&& win->w_buffer->b_locked > 0))
return; // window is already being closed
// Trigger WinClosed just before starting to free window-related resources.
trigger_winclosed(win);
// autocmd may have freed the window already.
if (!win_valid_any_tab(win))
return;
if (win->w_buffer != NULL)
// Close the link to the buffer.
close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0,