]> granicus.if.org Git - vim/commitdiff
patch 8.2.0747: cannot forcefully close all popups v8.2.0747
authorBram Moolenaar <Bram@vim.org>
Wed, 13 May 2020 11:40:16 +0000 (13:40 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 13 May 2020 11:40:16 +0000 (13:40 +0200)
Problem:    Cannot forcefully close all popups.
Solution:   Add the "force" argument to popup_clear().  Use it after running a
            test.  Put back the check for a popup when editing a file.

12 files changed:
runtime/doc/popup.txt
src/channel.c
src/evalfunc.c
src/ex_cmds.c
src/misc2.c
src/popupwin.c
src/proto/popupwin.pro
src/tag.c
src/testdir/runtest.vim
src/testdir/test_terminal.vim
src/version.c
src/window.c

index 9041f875402b18a1898a83de9e5355233b7aa7df..d0bf2c4f285cddb94a9409d07d81ce68a48a48ca 100644 (file)
@@ -236,8 +236,15 @@ popup_beval({what}, {options})                     *popup_beval()*
                        GetText()->popup_beval({})
 <
                                                        *popup_clear()*
-popup_clear()  Emergency solution to a misbehaving plugin: close all popup
+popup_clear([{force}])
+               Emergency solution to a misbehaving plugin: close all popup
                windows for the current tab and global popups.
+               Close callbacks are not invoked.
+               When {force} is not present this will fail if the current
+               window is a popup.
+               When {force} is present and |TRUE| the popup is also closed
+               when it is the current window.  If a terminal is running in a
+               popup it is killed.
 
 
 popup_close({id} [, {result}])                         *popup_close()*
index 0e432f9afa37a9cd0d2a476c59df48c9905770d9..1fcb8451cbf0cc10550430e9b239c7fe86b97b06 100644 (file)
@@ -156,9 +156,9 @@ ch_logfile(char_u *fname, char_u *opt)
     if (log_fd != NULL)
     {
        if (*fname != NUL)
-           ch_log(NULL, "closing, opening %s", fname);
+           ch_log(NULL, "closing this logfile, opening %s", fname);
        else
-           ch_log(NULL, "closing");
+           ch_log(NULL, "closing logfile");
        fclose(log_fd);
     }
 
index 1493291954238f882be4c84cc87ac50841a09a27..c0101162b19985af21102a017db89258eef67785 100644 (file)
@@ -704,7 +704,7 @@ static funcentry_T global_functions[] =
                        },
     {"popup_atcursor", 2, 2, FEARG_1,    ret_number,   PROP_FUNC(f_popup_atcursor)},
     {"popup_beval",    2, 2, FEARG_1,    ret_number,   PROP_FUNC(f_popup_beval)},
-    {"popup_clear",    0, 0, 0,          ret_void,     PROP_FUNC(f_popup_clear)},
+    {"popup_clear",    0, 1, 0,          ret_void,     PROP_FUNC(f_popup_clear)},
     {"popup_close",    1, 2, FEARG_1,    ret_void,     PROP_FUNC(f_popup_close)},
     {"popup_create",   2, 2, FEARG_1,    ret_number,   PROP_FUNC(f_popup_create)},
     {"popup_dialog",   2, 2, FEARG_1,    ret_number,   PROP_FUNC(f_popup_dialog)},
index f38bdacb63a9f795375dae7c95f1ea2f3d563372..9c55de3adf635f1c2da3cd646082a045d81c22b3 100644 (file)
@@ -2484,6 +2484,11 @@ do_ecmd(
     int                did_inc_redrawing_disabled = FALSE;
     long        *so_ptr = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so;
 
+#ifdef FEAT_PROP_POPUP
+    if (ERROR_IF_TERM_POPUP_WINDOW)
+       return FAIL;
+#endif
+
     if (eap != NULL)
        command = eap->do_ecmd_cmd;
     set_bufref(&old_curbuf, curbuf);
index 0ab6caffaf334235383d95383582c1c69a776999..50efde7f7bd740873566fa61ed4d13bc7bf62c24 100644 (file)
@@ -1069,13 +1069,9 @@ free_all_mem(void)
 # if defined(FEAT_BEVAL_TERM)
     ui_remove_balloon();
 # endif
-# if defined(FEAT_PROP_POPUP)
+# ifdef FEAT_PROP_POPUP
     if (curwin != NULL)
-    {
-       while (popup_is_popup(curwin))
-           popup_close_with_retval(curwin, 0);
-       close_all_popups();
-    }
+       close_all_popups(TRUE);
 # endif
 
     // Clear user commands (before deleting buffers).
index 5b346ac5bcae74a3f80f7ff347089fa64f224113..f1f9f6008a9358ea31c12d97bdae52f33468ec31 100644 (file)
@@ -2054,9 +2054,13 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
  * popup_clear()
  */
     void
-f_popup_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
+f_popup_clear(typval_T *argvars, typval_T *rettv UNUSED)
 {
-    close_all_popups();
+    int force = FALSE;
+
+    if (argvars[0].v_type != VAR_UNKNOWN)
+       force = (int)tv_get_number(&argvars[0]);
+    close_all_popups(force);
 }
 
 /*
@@ -2163,7 +2167,7 @@ popup_close_and_callback(win_T *wp, typval_T *arg)
        // Careful: This may make "wp" invalid.
        invoke_popup_callback(wp, arg);
 
-    popup_close(id);
+    popup_close(id, FALSE);
     CHECK_CURBUF;
 }
 
@@ -2250,7 +2254,7 @@ filter_handle_drag(win_T *wp, int c, typval_T *rettv)
 }
 
 /*
- * popup_filter_menu({text}, {options})
+ * popup_filter_menu({id}, {key})
  */
     void
 f_popup_filter_menu(typval_T *argvars, typval_T *rettv)
@@ -2305,7 +2309,7 @@ f_popup_filter_menu(typval_T *argvars, typval_T *rettv)
 }
 
 /*
- * popup_filter_yesno({text}, {options})
+ * popup_filter_yesno({id}, {key})
  */
     void
 f_popup_filter_yesno(typval_T *argvars, typval_T *rettv)
@@ -2534,7 +2538,7 @@ error_if_popup_window(int also_with_term UNUSED)
  * Return OK if the popup was closed, FAIL otherwise.
  */
     int
-popup_close(int id)
+popup_close(int id, int force)
 {
     win_T      *wp;
     tabpage_T  *tp;
@@ -2546,8 +2550,12 @@ popup_close(int id)
        {
            if (wp == curwin)
            {
-               error_for_popup_window();
-               return FAIL;
+               if (!force)
+               {
+                   error_for_popup_window();
+                   return FAIL;
+               }
+               win_enter(firstwin, FALSE);
            }
            if (prev == NULL)
                first_popupwin = wp->w_next;
@@ -2559,7 +2567,7 @@ popup_close(int id)
 
     // go through tab-local popups
     FOR_ALL_TABPAGES(tp)
-       if (popup_close_tabpage(tp, id) == OK)
+       if (popup_close_tabpage(tp, id, force) == OK)
            return OK;
     return FAIL;
 }
@@ -2568,7 +2576,7 @@ popup_close(int id)
  * Close a popup window with Window-id "id" in tabpage "tp".
  */
     int
-popup_close_tabpage(tabpage_T *tp, int id)
+popup_close_tabpage(tabpage_T *tp, int id, int force)
 {
     win_T      *wp;
     win_T      **root = &tp->tp_first_popupwin;
@@ -2579,8 +2587,12 @@ popup_close_tabpage(tabpage_T *tp, int id)
        {
            if (wp == curwin)
            {
-               error_for_popup_window();
-               return FAIL;
+               if (!force)
+               {
+                   error_for_popup_window();
+                   return FAIL;
+               }
+               win_enter(firstwin, FALSE);
            }
            if (prev == NULL)
                *root = wp->w_next;
@@ -2593,15 +2605,15 @@ popup_close_tabpage(tabpage_T *tp, int id)
 }
 
     void
-close_all_popups(void)
+close_all_popups(int force)
 {
-    if (ERROR_IF_ANY_POPUP_WINDOW)
+    if (!force && ERROR_IF_ANY_POPUP_WINDOW)
        return;
     while (first_popupwin != NULL)
-       if (popup_close(first_popupwin->w_id) == FAIL)
+       if (popup_close(first_popupwin->w_id, force) == FAIL)
            return;
     while (curtab->tp_first_popupwin != NULL)
-       if (popup_close(curtab->tp_first_popupwin->w_id) == FAIL)
+       if (popup_close(curtab->tp_first_popupwin->w_id, force) == FAIL)
            return;
 }
 
index 0147e680521f3c0df4878c33aab42baff7beb094..4fa3013f458305253f62d133e0e5aeb2b1b1486f 100644 (file)
@@ -34,9 +34,9 @@ void popup_show(win_T *wp);
 void f_popup_show(typval_T *argvars, typval_T *rettv);
 void f_popup_settext(typval_T *argvars, typval_T *rettv);
 int error_if_popup_window(int also_with_term);
-int popup_close(int id);
-int popup_close_tabpage(tabpage_T *tp, int id);
-void close_all_popups(void);
+int popup_close(int id, int force);
+int popup_close_tabpage(tabpage_T *tp, int id, int force);
+void close_all_popups(int force);
 void f_popup_move(typval_T *argvars, typval_T *rettv);
 void f_popup_setoptions(typval_T *argvars, typval_T *rettv);
 void f_popup_getpos(typval_T *argvars, typval_T *rettv);
index 40304e6696633f043d05fee87b36094e705007f0..a22a25996252ce84c18d6b42c422362872629e39 100644 (file)
--- a/src/tag.c
+++ b/src/tag.c
@@ -3684,7 +3684,7 @@ jumpto_tag(
 
            if (win_valid(curwin_save))
                win_enter(curwin_save, TRUE);
-           popup_close(wp->w_id);
+           popup_close(wp->w_id, FALSE);
        }
 #endif
     }
index 13d4784e4a804e82b7e02ad73e63434b73989998..b9d85f4bb1189cdd21425794ad125810beee9ddf 100644 (file)
@@ -188,9 +188,9 @@ func RunTheTest(test)
   au!
   au SwapExists * call HandleSwapExists()
 
-  " Close any stray popup windows
+  " Close any stray popup windows.
   if has('popupwin')
-    call popup_clear()
+    call popup_clear(1)
   endif
 
   " Close any extra tab pages and windows and make the current one not modified.
index b7791c8150b0002c074d39223872ba6b517efd81..33ff52fa489cec6175a11949bb6ebf0165920fdf 100644 (file)
@@ -2617,27 +2617,15 @@ endfunc
 
 func Test_term_nasty_callback()
   CheckExecutable sh
-  func OpenTerms()
-    set hidden
-    let g:buf0 = term_start('sh', #{hidden: 1})
-    call popup_create(g:buf0, {})
-    let g:buf1 = term_start('sh', #{hidden: 1, term_finish: 'close'})
-    call popup_create(g:buf1, {})
-    let g:buf2 = term_start(['sh', '-c'], #{curwin: 1, exit_cb: function('TermExit')})
-    call TermWait(g:buf2, 50)
-    call popup_close(win_getid())
-  endfunc
-  func TermExit(...)
-    let altbuf = bufnr('#')
-    call term_sendkeys(altbuf, "exit\<CR>")
-    call TermWait(altbuf)
-    call popup_close(win_getid())
-  endfunc
-  call OpenTerms()
 
-  call term_sendkeys(g:buf0, "exit\<CR>")
-  call TermWait(g:buf0, 50)
-  exe g:buf0 .. 'bwipe!'
+  set hidden
+  let g:buf0 = term_start('sh', #{hidden: 1})
+  call popup_create(g:buf0, {})
+  let g:buf1 = term_start('sh', #{hidden: 1, term_finish: 'close'})
+  call popup_create(g:buf1, {})
+  call assert_fails("call term_start(['sh', '-c'], #{curwin: 1})", 'E863:')
+
+  call popup_clear(1)
   set hidden&
 endfunc
 
index 37548b2baa79d53de6808fe402afd16170ed39ad..15956bbeb3ae23ebe3b0eb7f1490fa35aaa07997 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    747,
 /**/
     746,
 /**/
index 532d31431ec2469924418e07f9d094ce8a4461b7..ede2c6f281b8dfc06210f3ad621629cac3f6c0cd 100644 (file)
@@ -2766,9 +2766,6 @@ win_free_all(void)
        (void)win_free_mem(aucmd_win, &dummy, NULL);
        aucmd_win = NULL;
     }
-# ifdef FEAT_PROP_POPUP
-    close_all_popups();
-# endif
 
     while (firstwin != NULL)
        (void)win_free_mem(firstwin, &dummy, NULL);
@@ -3801,7 +3798,7 @@ free_tabpage(tabpage_T *tp)
 # endif
 # ifdef FEAT_PROP_POPUP
     while (tp->tp_first_popupwin != NULL)
-       popup_close_tabpage(tp, tp->tp_first_popupwin->w_id);
+       popup_close_tabpage(tp, tp->tp_first_popupwin->w_id, TRUE);
 #endif
     for (idx = 0; idx < SNAP_COUNT; ++idx)
        clear_snapshot(tp, idx);