]> granicus.if.org Git - vim/commitdiff
patch 8.2.0327: crash when opening and closing two popup terminal windows v8.2.0327
authorBram Moolenaar <Bram@vim.org>
Fri, 28 Feb 2020 18:11:18 +0000 (19:11 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 28 Feb 2020 18:11:18 +0000 (19:11 +0100)
Problem:    Crash when opening and closing two popup terminal windows.
Solution:   Check that prevwin is valid. (closes #5707)

src/popupwin.c
src/testdir/test_terminal.vim
src/version.c

index 407837850d750f0bf0fa45e0bd4f6e0206760cfb..0e0260b90044b7b167290433a91aaa2126a25829 100644 (file)
@@ -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
 
index 20d27bc02226f0c0aca30ac02bb496a6e49af618..fb717f603f73be08261fb8269f74fa27e432af01 100644 (file)
@@ -2391,6 +2391,17 @@ func Test_terminal_in_popup()
   call delete('XtermPopup')
 endfunc
 
+func Test_double_popup_terminal()
+  let buf1 = term_start(&shell, #{hidden: 1})
+  let win1 = popup_create(buf1, {})
+  let buf2 = term_start(&shell, #{hidden: 1})
+  let win2 = popup_create(buf2, {})
+  call popup_close(win1)
+  call popup_close(win2)
+  exe buf1 .. 'bwipe!'
+  exe buf2 .. 'bwipe!'
+endfunc
+
 func Test_issue_5607()
   let wincount = winnr('$')
   exe 'terminal' &shell &shellcmdflag 'exit'
index ad279466ef092139bdb1c613f9081cc5981c98de..693a1d6ea8f72f362fb6b7ad2f021bfbda8e3d48 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    327,
 /**/
     326,
 /**/