#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
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'