]> granicus.if.org Git - vim/commitdiff
patch 8.2.0748: cannot get a list of all popups v8.2.0748
authorBram Moolenaar <Bram@vim.org>
Wed, 13 May 2020 14:34:15 +0000 (16:34 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 13 May 2020 14:34:15 +0000 (16:34 +0200)
Problem:    Cannot get a list of all popups.
Solution:   Add popup_list().  Use it in the test runner.

runtime/doc/eval.txt
runtime/doc/popup.txt
src/evalfunc.c
src/popupwin.c
src/proto/popupwin.pro
src/testdir/runtest.vim
src/testdir/test_popupwin.vim
src/version.c

index 8086bd560232a223cd9005d9889e0459dd2ff495..8259e9920b31c3c834717e28e5a4857659fd482c 100644 (file)
@@ -2627,6 +2627,8 @@ popup_findpreview()               Number  get window ID of preview popup window
 popup_getoptions({id})         Dict    get options of popup window {id}
 popup_getpos({id})             Dict    get position of popup window {id}
 popup_hide({id})               none    hide popup menu {id}
+popup_list()                   List    get a list of window IDs of al popups
+popup_locate({row}, {col})     Number  get window ID of popup at position
 popup_menu({what}, {options})  Number  create a popup window used as a menu
 popup_move({id}, {options})    none    set position of popup window {id}
 popup_notification({what}, {options})
index d0bf2c4f285cddb94a9409d07d81ce68a48a48ca..5950c4753dc5be2bf3058290f93d9059a66aa4a3 100644 (file)
@@ -198,6 +198,7 @@ Other:
        |popup_getoptions()|    get current options for a popup
        |popup_getpos()|        get actual position and size of a popup
        |popup_locate()|        find popup window at a screen position
+       |popup_list()|          get list of all popups
 
 
 DETAILS                                                *popup-function-details*
@@ -423,6 +424,10 @@ popup_hide({id})                                           *popup_hide()*
                Can also be used as a |method|: >
                        GetPopup()->popup_hide()
 
+popup_list()                                            *popup_list()*
+               Return a List with the |window-ID| of all existing popups.
+
+
 popup_locate({row}, {col})                              *popup_locate()*
                Return the |window-ID| of the popup at screen position {row}
                and {col}.  If there are multiple popups the one with the
index c0101162b19985af21102a017db89258eef67785..c499890d9b192f2be93ee1daf7fb336963badafb 100644 (file)
@@ -715,6 +715,7 @@ static funcentry_T global_functions[] =
     {"popup_getoptions", 1, 1, FEARG_1,          ret_dict_any, PROP_FUNC(f_popup_getoptions)},
     {"popup_getpos",   1, 1, FEARG_1,    ret_dict_any, PROP_FUNC(f_popup_getpos)},
     {"popup_hide",     1, 1, FEARG_1,    ret_void,     PROP_FUNC(f_popup_hide)},
+    {"popup_list",     0, 0, 0,          ret_list_number, PROP_FUNC(f_popup_list)},
     {"popup_locate",   2, 2, 0,          ret_number,   PROP_FUNC(f_popup_locate)},
     {"popup_menu",     2, 2, FEARG_1,    ret_number,   PROP_FUNC(f_popup_menu)},
     {"popup_move",     2, 2, FEARG_1,    ret_void,     PROP_FUNC(f_popup_move)},
index f1f9f6008a9358ea31c12d97bdae52f33468ec31..a244c32368f6996eceac6ae12ea1d8de7dfaedc5 100644 (file)
@@ -2720,6 +2720,25 @@ f_popup_getpos(typval_T *argvars, typval_T *rettv)
        hash_unlock(&dict->dv_hashtab);
     }
 }
+
+/*
+ * popup_list()
+ */
+    void
+f_popup_list(typval_T *argvars UNUSED, typval_T *rettv)
+{
+    win_T      *wp;
+    tabpage_T  *tp;
+
+    if (rettv_list_alloc(rettv) != OK)
+       return;
+    FOR_ALL_POPUPWINS(wp)
+       list_append_number(rettv->vval.v_list, wp->w_id);
+    FOR_ALL_TABPAGES(tp)
+       FOR_ALL_POPUPWINS_IN_TAB(tp, wp)
+           list_append_number(rettv->vval.v_list, wp->w_id);
+}
+
 /*
  * popup_locate({row}, {col})
  */
index 4fa3013f458305253f62d133e0e5aeb2b1b1486f..02cdce33ab93d2803f95b9376ead65ff4eb2a5b2 100644 (file)
@@ -40,6 +40,7 @@ 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);
+void f_popup_list(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_term_popup_window(void);
index b9d85f4bb1189cdd21425794ad125810beee9ddf..b1e05288b118154bd4f81782de3c68f1e896029d 100644 (file)
@@ -188,8 +188,9 @@ func RunTheTest(test)
   au!
   au SwapExists * call HandleSwapExists()
 
-  " Close any stray popup windows.
+  " Check for and close any stray popup windows.
   if has('popupwin')
+    call assert_equal([], popup_list())
     call popup_clear(1)
   endif
 
index 5eecb193c115e10d5f5cd93c15dfa7c8c501c8e0..a664346df5efd7edcff970239ae797cce0d496ee 100644 (file)
@@ -428,7 +428,7 @@ func Test_popup_nospace()
   call delete('XtestPopupNospace')
 endfunc
 
-func Test_popup_firstline()
+func Test_popup_firstline_dump()
   CheckScreendump
 
   let lines =<< trim END
@@ -449,7 +449,9 @@ func Test_popup_firstline()
   " clean up
   call StopVimInTerminal(buf)
   call delete('XtestPopupFirstline')
+endfunc
 
+func Test_popup_firstline()
   let winid = popup_create(['1111', '222222', '33333', '44444'], #{
        \ maxheight: 2,
        \ firstline: 3,
@@ -491,6 +493,7 @@ func Test_popup_firstline()
   call popup_setoptions(winid, #{line: 3})
   call assert_equal(0, popup_getoptions(winid).firstline)
   call assert_equal(10, popup_getpos(winid).firstline)
+  call popup_close(winid)
 
   " CTRL-D scrolls down half a page
   let winid = popup_create(['xxx']->repeat(50), #{
@@ -826,10 +829,13 @@ func Test_popup_in_tab()
 endfunc
 
 func Test_popup_valid_arguments()
+  call assert_equal(0, len(popup_list()))
+
   " Zero value is like the property wasn't there
   let winid = popup_create("text", #{col: 0})
   let pos = popup_getpos(winid)
   call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
+  call assert_equal([winid], popup_list())
   call popup_clear()
 
   " using cursor column has minimum value of 1
@@ -1619,12 +1625,14 @@ func Test_popup_empty()
   let pos = popup_getpos(winid)
   call assert_equal(5, pos.width)
   call assert_equal(5, pos.height)
+  call popup_close(winid)
 
   let winid = popup_create([], #{border: []})
   redraw
   let pos = popup_getpos(winid)
   call assert_equal(3, pos.width)
   call assert_equal(3, pos.height)
+  call popup_close(winid)
 endfunc
 
 func Test_popup_never_behind()
@@ -3323,8 +3331,9 @@ func Test_popupwin_atcursor_far_right()
   set signcolumn=yes
   call setline(1, repeat('=', &columns))
   normal! ggg$
-  call popup_atcursor(repeat('x', 500), #{moved: 'any', border: []})
+  let winid = popup_atcursor(repeat('x', 500), #{moved: 'any', border: []})
 
+  call popup_close(winid)
   bwipe!
   set signcolumn&
 endfunc
index 15956bbeb3ae23ebe3b0eb7f1490fa35aaa07997..7881e3211ece182dd2a41c663cd275aa15c7e730 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    748,
 /**/
     747,
 /**/