Skip to content

Commit a139615

Browse files
committed
patch 8.1.2193: popup_setoptions(popup_getoptions()) does not work
Problem: Popup_setoptions(popup_getoptions()) does not work. Solution: Also accept a list with three entries for "moved" and "mousemoved". (closes #5081)
1 parent dca7abe commit a139615

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

runtime/doc/popup.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ popup_notification({what}, {options}) *popup_notification()*
474474
popup_show({id}) *popup_show()*
475475
If {id} is a hidden popup, show it now.
476476
For {id} see `popup_hide()`.
477+
If {id} is the info popup it will be positioned next to the
478+
current popup menu item.
477479

478480

479481
popup_setoptions({id}, {options}) *popup_setoptions()*
@@ -680,8 +682,13 @@ The second argument of |popup_create()| is a dictionary with options:
680682
- "expr": if the cursor moved outside |<cexpr>|
681683
- [{start}, {end}]: if the cursor moved before column
682684
{start} or after {end}
685+
- [{lnum}, {start}, {end}]: if the cursor moved away
686+
from line {lnum}, before column {start} or after
687+
{end}
683688
The popup also closes if the cursor moves to another
684689
line or to another window.
690+
mousemoved Like "moved" but referring to the mouse pointer
691+
position
685692
cursorline non-zero: Highlight the cursor line. Also scrolls the
686693
text to show this line (only works properly
687694
when 'wrap' is off).

src/popupwin.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,28 @@ handle_moved_argument(win_T *wp, dictitem_T *di, int mousemoved)
493493
}
494494
else if (di->di_tv.v_type == VAR_LIST
495495
&& di->di_tv.vval.v_list != NULL
496-
&& di->di_tv.vval.v_list->lv_len == 2)
496+
&& (di->di_tv.vval.v_list->lv_len == 2
497+
|| di->di_tv.vval.v_list->lv_len == 3))
497498
{
498-
list_T *l = di->di_tv.vval.v_list;
499-
int mincol = tv_get_number(&l->lv_first->li_tv);
500-
int maxcol = tv_get_number(&l->lv_first->li_next->li_tv);
499+
list_T *l = di->di_tv.vval.v_list;
500+
listitem_T *li = l->lv_first;
501+
int mincol;
502+
int maxcol;
501503

504+
if (di->di_tv.vval.v_list->lv_len == 3)
505+
{
506+
varnumber_T nr = tv_get_number(&l->lv_first->li_tv);
507+
508+
// Three numbers, might be from popup_getoptions().
509+
if (mousemoved)
510+
wp->w_popup_mouse_row = nr;
511+
else
512+
wp->w_popup_lnum = nr;
513+
li = li->li_next;
514+
}
515+
516+
mincol = tv_get_number(&li->li_tv);
517+
maxcol = tv_get_number(&li->li_next->li_tv);
502518
if (mousemoved)
503519
{
504520
wp->w_popup_mouse_mincol = mincol;

src/testdir/test_popupwin.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ func Test_popup_with_border_and_padding()
170170
call assert_equal(['Top', 'Right', 'Bottom', 'Left'], options.borderhighlight)
171171
call assert_equal(['1', '^', '2', '>', '3', 'v', '4', '<'], options.borderchars)
172172

173+
" Check that popup_setoptions() takes the output of popup_getoptions()
174+
call popup_setoptions(winid, options)
175+
call assert_equal(options, popup_getoptions(winid))
176+
173177
let winid = popup_create('hello both', #{line: 3, col: 8, border: [], padding: []})
174178
call assert_equal(#{
175179
\ line: 3,

src/version.c

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

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
2193,
744746
/**/
745747
2192,
746748
/**/

0 commit comments

Comments
 (0)