summaryrefslogtreecommitdiffstats
path: root/src/autocmd.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-11-07 16:58:59 +0100
committerBram Moolenaar <Bram@vim.org>2020-11-07 16:58:59 +0100
commitcbcd9cbd77acc8cc97c0d44683d96c01d3dd0fa7 (patch)
tree0327591c6c155fec6e557463815968f90bab3e0a /src/autocmd.c
parent46f479c756c0255e3b6d473590c1857678eff5c6 (diff)
patch 8.2.1966: popup becomes current window after closing a terminal windowv8.2.1966
Problem: Popup becomes current window after closing a terminal window. Solution: When restoring the window after executing autocommands, check that the window ID is still the same. (Naruhiko Nishino, closes #7272)
Diffstat (limited to 'src/autocmd.c')
-rw-r--r--src/autocmd.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/autocmd.c b/src/autocmd.c
index be35845c9d..a82659f654 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -1433,9 +1433,9 @@ aucmd_prepbuf(
// window. Expect a few side effects...
win = curwin;
- aco->save_curwin = curwin;
+ aco->save_curwin_id = curwin->w_id;
aco->save_curbuf = curbuf;
- aco->save_prevwin = prevwin;
+ aco->save_prevwin_id = prevwin == NULL ? 0 : prevwin->w_id;
if (win != NULL)
{
// There is a window for "buf" in the current tab page, make it the
@@ -1481,7 +1481,7 @@ aucmd_prepbuf(
curwin = aucmd_win;
}
curbuf = buf;
- aco->new_curwin = curwin;
+ aco->new_curwin_id = curwin->w_id;
set_bufref(&aco->new_curbuf, curbuf);
}
@@ -1493,7 +1493,8 @@ aucmd_prepbuf(
aucmd_restbuf(
aco_save_T *aco) // structure holding saved values
{
- int dummy;
+ int dummy;
+ win_T *save_curwin;
if (aco->use_aucmd_win)
{
@@ -1533,8 +1534,9 @@ win_found:
(void)win_comp_pos(); // recompute window positions
unblock_autocmds();
- if (win_valid(aco->save_curwin))
- curwin = aco->save_curwin;
+ save_curwin = win_find_by_id(aco->save_curwin_id);
+ if (save_curwin != NULL)
+ curwin = save_curwin;
else
// Hmm, original window disappeared. Just use the first one.
curwin = firstwin;
@@ -1543,9 +1545,7 @@ win_found:
// May need to restore insert mode for a prompt buffer.
entering_window(curwin);
#endif
-
- if (win_valid(aco->save_prevwin))
- prevwin = aco->save_prevwin;
+ prevwin = win_find_by_id(aco->save_prevwin_id);
#ifdef FEAT_EVAL
vars_clear(&aucmd_win->w_vars->dv_hashtab); // free all w: variables
hash_init(&aucmd_win->w_vars->dv_hashtab); // re-use the hashtab
@@ -1571,13 +1571,15 @@ win_found:
}
else
{
- // restore curwin
- if (win_valid(aco->save_curwin))
+ // Restore curwin. Use the window ID, a window may have been closed
+ // and the memory re-used for another one.
+ save_curwin = win_find_by_id(aco->save_curwin_id);
+ if (save_curwin != NULL)
{
// Restore the buffer which was previously edited by curwin, if
// it was changed, we are still the same window and the buffer is
// valid.
- if (curwin == aco->new_curwin
+ if (curwin->w_id == aco->new_curwin_id
&& curbuf != aco->new_curbuf.br_buf
&& bufref_valid(&aco->new_curbuf)
&& aco->new_curbuf.br_buf->b_ml.ml_mfp != NULL)
@@ -1592,10 +1594,9 @@ win_found:
++curbuf->b_nwindows;
}
- curwin = aco->save_curwin;
+ curwin = save_curwin;
curbuf = curwin->w_buffer;
- if (win_valid(aco->save_prevwin))
- prevwin = aco->save_prevwin;
+ prevwin = win_find_by_id(aco->save_prevwin_id);
// In case the autocommand moves the cursor to a position that
// does not exist in curbuf.
check_cursor();