]> granicus.if.org Git - vim/commitdiff
patch 8.1.1673: cannot easily find the popup window at a certain position v8.1.1673
authorBram Moolenaar <Bram@vim.org>
Fri, 12 Jul 2019 19:07:54 +0000 (21:07 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 12 Jul 2019 19:07:54 +0000 (21:07 +0200)
Problem:    Cannot easily find the popup window at a certain position.
Solution:   Add popup_locate().

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

index ba4dc3fc155d285db8a537e1257c787cc9b2f54a..b0397a35e8badb6c3f4b0fd8bb8f4569af778718 100644 (file)
@@ -170,6 +170,7 @@ Filter functions:
 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
 
 
 DETAILS                                                *popup-function-details*
@@ -343,6 +344,13 @@ popup_hide({id})                                           *popup_hide()*
                exists but is not a popup window an error is given. *E993*
 
 
+popup_locate({row}, {col})                              *popup_locate()*
+               Return the |window-ID| of the popup at screen positoin {row}
+               and {col}.  If there are multiple popups the one with the
+               highest zindex is returned.  If there are no popups at this
+               position then zero is returned.
+
+
 popup_menu({what}, {options})                           *popup_menu()*
                Show the {what} near the cursor, handle selecting one of the
                items with cursorkeys, and close it an item is selected with
index 4ee0d5d9a12a6960cb6da647e496a25c3b9f798e..43c8028b6ed8ffb87c2755a85d950644e1ab78f3 100644 (file)
@@ -781,6 +781,7 @@ static struct fst
     {"popup_getoptions", 1, 1, f_popup_getoptions},
     {"popup_getpos",   1, 1, f_popup_getpos},
     {"popup_hide",     1, 1, f_popup_hide},
+    {"popup_locate",   2, 2, f_popup_locate},
     {"popup_menu",     2, 2, f_popup_menu},
     {"popup_move",     2, 2, f_popup_move},
     {"popup_notification", 2, 2, f_popup_notification},
index aa19a5d63d6cba94849d601fb302a19be3100758..ea85588f2f570d41071aabff4c6f08f66ce54392 100644 (file)
@@ -1890,6 +1890,20 @@ f_popup_getpos(typval_T *argvars, typval_T *rettv)
                      win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0);
     }
 }
+/*
+ * popup_locate({row}, {col})
+ */
+    void
+f_popup_locate(typval_T *argvars, typval_T *rettv)
+{
+    int                row = tv_get_number(&argvars[0]) - 1;
+    int                col = tv_get_number(&argvars[1]) - 1;
+    win_T      *wp;
+
+    wp = mouse_find_win(&row, &col, FIND_POPUP);
+    if (WIN_IS_POPUP(wp))
+       rettv->vval.v_number = wp->w_id;
+}
 
 /*
  * For popup_getoptions(): add a "border" or "padding" entry to "dict".
index 7733368578334d789c057ef3ee158104021f9706..d1267e02246560b1ebd98c7114b1f50ba6d10fb9 100644 (file)
@@ -29,6 +29,7 @@ void close_all_popups(void);
 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_locate(typval_T *argvars, typval_T *rettv);
 void f_popup_getoptions(typval_T *argvars, typval_T *rettv);
 int error_if_popup_window(void);
 void popup_reset_handled(void);
index 7b7b1bd75520ddd34749ca1d4f131a4f3a7b913e..a55e913a9a92120617eaa2c17d0fe53a6c41ca11 100644 (file)
@@ -713,7 +713,7 @@ func Test_popup_time()
   topleft vnew
   call setline(1, 'hello')
 
-  call popup_create('world', {
+  let winid = popup_create('world', {
        \ 'line': 1,
        \ 'col': 1,
        \ 'minwidth': 20,
@@ -723,6 +723,11 @@ func Test_popup_time()
   let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
   call assert_equal('world', line)
 
+  call assert_equal(winid, popup_locate(1, 1))
+  call assert_equal(winid, popup_locate(1, 20))
+  call assert_equal(0, popup_locate(1, 21))
+  call assert_equal(0, popup_locate(2, 1))
+
   sleep 700m
   redraw
   let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
index ea5de7db29ac383d15bd164977cd0eec89d49b23..07c0d7ae9bd2cd73e82fc96ad1d872855f21b94e 100644 (file)
@@ -777,6 +777,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1673,
 /**/
     1672,
 /**/