Skip to content

Commit b4f0628

Browse files
committed
patch 8.1.1673: cannot easily find the popup window at a certain position
Problem: Cannot easily find the popup window at a certain position. Solution: Add popup_locate().
1 parent d94ac0c commit b4f0628

6 files changed

Lines changed: 32 additions & 1 deletion

File tree

runtime/doc/popup.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Filter functions:
170170
Other:
171171
|popup_getoptions()| get current options for a popup
172172
|popup_getpos()| get actual position and size of a popup
173+
|popup_locate()| find popup window at a screen position
173174

174175

175176
DETAILS *popup-function-details*
@@ -343,6 +344,13 @@ popup_hide({id}) *popup_hide()*
343344
exists but is not a popup window an error is given. *E993*
344345

345346

347+
popup_locate({row}, {col}) *popup_locate()*
348+
Return the |window-ID| of the popup at screen positoin {row}
349+
and {col}. If there are multiple popups the one with the
350+
highest zindex is returned. If there are no popups at this
351+
position then zero is returned.
352+
353+
346354
popup_menu({what}, {options}) *popup_menu()*
347355
Show the {what} near the cursor, handle selecting one of the
348356
items with cursorkeys, and close it an item is selected with

src/evalfunc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ static struct fst
781781
{"popup_getoptions", 1, 1, f_popup_getoptions},
782782
{"popup_getpos", 1, 1, f_popup_getpos},
783783
{"popup_hide", 1, 1, f_popup_hide},
784+
{"popup_locate", 2, 2, f_popup_locate},
784785
{"popup_menu", 2, 2, f_popup_menu},
785786
{"popup_move", 2, 2, f_popup_move},
786787
{"popup_notification", 2, 2, f_popup_notification},

src/popupwin.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,20 @@ f_popup_getpos(typval_T *argvars, typval_T *rettv)
18901890
win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0);
18911891
}
18921892
}
1893+
/*
1894+
* popup_locate({row}, {col})
1895+
*/
1896+
void
1897+
f_popup_locate(typval_T *argvars, typval_T *rettv)
1898+
{
1899+
int row = tv_get_number(&argvars[0]) - 1;
1900+
int col = tv_get_number(&argvars[1]) - 1;
1901+
win_T *wp;
1902+
1903+
wp = mouse_find_win(&row, &col, FIND_POPUP);
1904+
if (WIN_IS_POPUP(wp))
1905+
rettv->vval.v_number = wp->w_id;
1906+
}
18931907

18941908
/*
18951909
* For popup_getoptions(): add a "border" or "padding" entry to "dict".

src/proto/popupwin.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void close_all_popups(void);
2929
void f_popup_move(typval_T *argvars, typval_T *rettv);
3030
void f_popup_setoptions(typval_T *argvars, typval_T *rettv);
3131
void f_popup_getpos(typval_T *argvars, typval_T *rettv);
32+
void f_popup_locate(typval_T *argvars, typval_T *rettv);
3233
void f_popup_getoptions(typval_T *argvars, typval_T *rettv);
3334
int error_if_popup_window(void);
3435
void popup_reset_handled(void);

src/testdir/test_popupwin.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ func Test_popup_time()
713713
topleft vnew
714714
call setline(1, 'hello')
715715

716-
call popup_create('world', {
716+
let winid = popup_create('world', {
717717
\ 'line': 1,
718718
\ 'col': 1,
719719
\ 'minwidth': 20,
@@ -723,6 +723,11 @@ func Test_popup_time()
723723
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
724724
call assert_equal('world', line)
725725

726+
call assert_equal(winid, popup_locate(1, 1))
727+
call assert_equal(winid, popup_locate(1, 20))
728+
call assert_equal(0, popup_locate(1, 21))
729+
call assert_equal(0, popup_locate(2, 1))
730+
726731
sleep 700m
727732
redraw
728733
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,8 @@ static char *(features[]) =
777777

778778
static int included_patches[] =
779779
{ /* Add new patch number below this line */
780+
/**/
781+
1673,
780782
/**/
781783
1672,
782784
/**/

0 commit comments

Comments
 (0)