summaryrefslogtreecommitdiff
path: root/src/popupwin.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-02-28 19:11:18 +0100
committerBram Moolenaar <Bram@vim.org>2020-02-28 19:11:18 +0100
commit80ae880f5fed8022c69d05dd1efee49259929cb5 (patch)
treec5219a960c034b06e4471c0dd383ac232b04547c /src/popupwin.c
parentd5aec0ced17f8f60761128bff32e54ad2d1d57ef (diff)
downloadvim-git-8.2.0327.tar.gz
patch 8.2.0327: crash when opening and closing two popup terminal windowsv8.2.0327
Problem: Crash when opening and closing two popup terminal windows. Solution: Check that prevwin is valid. (closes #5707)
Diffstat (limited to 'src/popupwin.c')
-rw-r--r--src/popupwin.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/popupwin.c b/src/popupwin.c
index 407837850..0e0260b90 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -2114,9 +2114,31 @@ popup_close_and_callback(win_T *wp, typval_T *arg)
#ifdef FEAT_TERMINAL
if (wp == curwin && curbuf->b_term != NULL)
{
- // Closing popup window with a terminal: put focus back on the previous
- // window.
- win_enter(prevwin, FALSE);
+ win_T *owp;
+
+ // Closing popup window with a terminal: put focus back on the first
+ // that works:
+ // - another popup window with a terminal
+ // - the previous window
+ // - the first one.
+ for (owp = first_popupwin; owp != NULL; owp = owp->w_next)
+ if (owp != curwin && owp->w_buffer->b_term != NULL)
+ break;
+ if (owp != NULL)
+ win_enter(owp, FALSE);
+ else
+ {
+ for (owp = curtab->tp_first_popupwin; owp != NULL;
+ owp = owp->w_next)
+ if (owp != curwin && owp->w_buffer->b_term != NULL)
+ break;
+ if (owp != NULL)
+ win_enter(owp, FALSE);
+ else if (win_valid(prevwin))
+ win_enter(prevwin, FALSE);
+ else
+ win_enter(firstwin, FALSE);
+ }
}
#endif