patch 8.2.0194: some commands can cause problems in terminal popup

Problem:    Some commands can cause problems in terminal popup.
Solution:   Disallow more commands.
diff --git a/src/arglist.c b/src/arglist.c
index 942da86..ad404d8 100644
--- a/src/arglist.c
+++ b/src/arglist.c
@@ -638,7 +638,7 @@
     char_u	*p;
     int		old_arg_idx = curwin->w_arg_idx;
 
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
     if (argn < 0 || argn >= ARGCOUNT)
     {
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 80cc930..645ad0c 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -4633,7 +4633,7 @@
     static void
 ex_bunload(exarg_T *eap)
 {
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
     eap->errmsg = do_bufdel(
 	    eap->cmdidx == CMD_bdelete ? DOBUF_DEL
@@ -4649,7 +4649,7 @@
     static void
 ex_buffer(exarg_T *eap)
 {
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
     if (*eap->arg)
 	eap->errmsg = e_trailing;
@@ -4683,7 +4683,7 @@
     static void
 ex_bnext(exarg_T *eap)
 {
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
 
     goto_buffer(eap, DOBUF_CURRENT, FORWARD, (int)eap->line2);
@@ -4700,7 +4700,7 @@
     static void
 ex_bprevious(exarg_T *eap)
 {
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
 
     goto_buffer(eap, DOBUF_CURRENT, BACKWARD, (int)eap->line2);
@@ -4717,7 +4717,7 @@
     static void
 ex_brewind(exarg_T *eap)
 {
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
 
     goto_buffer(eap, DOBUF_FIRST, FORWARD, 0);
@@ -4732,7 +4732,7 @@
     static void
 ex_blast(exarg_T *eap)
 {
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
 
     goto_buffer(eap, DOBUF_LAST, BACKWARD, 0);
@@ -5762,7 +5762,7 @@
 		       || eap->cmdidx == CMD_tabfind
 		       || eap->cmdidx == CMD_tabnew;
 
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
 
 #ifdef FEAT_GUI
@@ -6145,7 +6145,8 @@
     int		need_hide;
     int		exmode_was = exmode_active;
 
-    if (eap->cmdidx != CMD_pedit && ERROR_IF_POPUP_WINDOW)
+    if ((eap->cmdidx != CMD_pedit && ERROR_IF_POPUP_WINDOW)
+						 || ERROR_IF_TERM_POPUP_WINDOW)
 	return;
     /*
      * ":vi" command ends Ex mode.
diff --git a/src/macros.h b/src/macros.h
index 68e3f97..b719462 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -344,9 +344,11 @@
 
 // Give an error in curwin is a popup window and evaluate to TRUE.
 #ifdef FEAT_PROP_POPUP
-# define ERROR_IF_POPUP_WINDOW error_if_popup_window()
+# define ERROR_IF_POPUP_WINDOW error_if_popup_window(FALSE)
+# define ERROR_IF_ANY_POPUP_WINDOW error_if_popup_window(TRUE)
 #else
 # define ERROR_IF_POPUP_WINDOW 0
+# define ERROR_IF_ANY_POPUP_WINDOW 0
 #endif
 #if defined(FEAT_PROP_POPUP) && defined(FEAT_TERMINAL)
 # define ERROR_IF_TERM_POPUP_WINDOW error_if_term_popup_window()
diff --git a/src/popupwin.c b/src/popupwin.c
index cb33dc4..d4f6026 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -2360,7 +2360,7 @@
     int		id = (int)tv_get_number(argvars);
     win_T	*wp;
 
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
 
     wp = find_popup_win(id);
@@ -2511,7 +2511,7 @@
     void
 close_all_popups(void)
 {
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
     while (first_popupwin != NULL)
 	popup_close(first_popupwin->w_id);
@@ -2845,14 +2845,14 @@
 }
 
     int
-error_if_popup_window()
+error_if_popup_window(int also_with_term UNUSED)
 {
     // win_execute() may set "curwin" to a popup window temporarily, but many
     // commands are disallowed then.  When a terminal runs in the popup most
     // things are allowed.
     if (WIN_IS_POPUP(curwin)
 # ifdef FEAT_TERMINAL
-	    && curbuf->b_term == NULL
+	    && (also_with_term || curbuf->b_term == NULL)
 # endif
 	    )
     {
diff --git a/src/proto/popupwin.pro b/src/proto/popupwin.pro
index bfbd883..7608f32 100644
--- a/src/proto/popupwin.pro
+++ b/src/proto/popupwin.pro
@@ -41,7 +41,7 @@
 void f_popup_getpos(typval_T *argvars, typval_T *rettv);
 void f_popup_locate(typval_T *argvars, typval_T *rettv);
 void f_popup_getoptions(typval_T *argvars, typval_T *rettv);
-int error_if_popup_window(void);
+int error_if_popup_window(int also_with_term);
 int error_if_term_popup_window(void);
 void popup_reset_handled(int handled_flag);
 win_T *find_next_popup(int lowest, int handled_flag);
diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index 00f0bfe..7fda9f6 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -2357,7 +2357,7 @@
   call VerifyScreenDump(buf, 'Test_terminal_popup_3', {})
  
   call term_sendkeys(buf, ":q\<CR>")
-  call term_wait(buf, 50)  " wait for terminal to vanish
+  call term_wait(buf, 100)  " wait for terminal to vanish
 
   call StopVimInTerminal(buf)
   call delete('XtermPopup')
diff --git a/src/version.c b/src/version.c
index 657e137..549c78c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -743,6 +743,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    194,
+/**/
     193,
 /**/
     192,
diff --git a/src/window.c b/src/window.c
index 6317c37..aeafb26 100644
--- a/src/window.c
+++ b/src/window.c
@@ -122,7 +122,7 @@
 #endif
     char_u	cbuf[40];
 
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
 
 #ifdef FEAT_CMDWIN
@@ -784,7 +784,7 @@
     int
 win_split(int size, int flags)
 {
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return FAIL;
 
     // When the ":tab" modifier was used open a new tab page instead.
@@ -1574,7 +1574,7 @@
     win_T	*wp2;
     int		temp;
 
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
     if (ONE_WINDOW)	    // just one window
     {
@@ -2441,7 +2441,7 @@
     int		had_diffmode = win->w_p_diff;
 #endif
 
-    if (ERROR_IF_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return FAIL;
 
     if (last_window())
@@ -4344,7 +4344,7 @@
 #endif
 
 #ifdef FEAT_PROP_POPUP
-    if (ERROR_IF_POPUP_WINDOW || ERROR_IF_TERM_POPUP_WINDOW)
+    if (ERROR_IF_ANY_POPUP_WINDOW)
 	return;
     if (popup_is_popup(wp))
     {