Skip to content

Commit 7b3d939

Browse files
committed
patch 8.1.2164: stuck when using "j" in a popupwin with popup_filter_menu
Problem: Stuck when using "j" in a popupwin with popup_filter_menu if a line wraps. Solution: Check the cursor line is visible. (closes #4577)
1 parent b2fe1d6 commit 7b3d939

5 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/popupwin.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ check_highlight(dict_T *dict, char *name, char_u **pval)
535535
}
536536

537537
/*
538-
* Scroll to show the line with the cursor. This assumes lines don't wrap.
538+
* Scroll to show the line with the cursor.
539539
*/
540540
static void
541541
popup_show_curline(win_T *wp)
@@ -550,6 +550,11 @@ popup_show_curline(win_T *wp)
550550
wp->w_topline = 1;
551551
else if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count)
552552
wp->w_topline = wp->w_buffer->b_ml.ml_line_count;
553+
while (wp->w_topline < wp->w_cursor.lnum
554+
&& wp->w_topline < wp->w_buffer->b_ml.ml_line_count
555+
&& plines_m_win(wp, wp->w_topline, wp->w_cursor.lnum)
556+
> wp->w_height)
557+
++wp->w_topline;
553558
}
554559

555560
// Don't use "firstline" now.
@@ -1041,6 +1046,7 @@ popup_adjust_position(win_T *wp)
10411046
linenr_T lnum;
10421047
int wrapped = 0;
10431048
int maxwidth;
1049+
int used_maxwidth = FALSE;
10441050
int maxspace;
10451051
int center_vert = FALSE;
10461052
int center_hor = FALSE;
@@ -1208,6 +1214,7 @@ popup_adjust_position(win_T *wp)
12081214
++wrapped;
12091215
len -= maxwidth;
12101216
wp->w_width = maxwidth;
1217+
used_maxwidth = TRUE;
12111218
}
12121219
}
12131220
else if (len > maxwidth
@@ -1259,6 +1266,8 @@ popup_adjust_position(win_T *wp)
12591266
{
12601267
++right_extra;
12611268
++extra_width;
1269+
if (used_maxwidth)
1270+
maxwidth -= 2; // try to show the scrollbar
12621271
}
12631272

12641273
minwidth = wp->w_minwidth;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>1+0&#ffffff0| @73
2+
|2| @73
3+
|╔+0#0000001#ffd7ff255|═@73
4+
|║| |o+0&#e0e0e08|n|e| @67| +0&#ffd7ff255| +0#0000000#0000001
5+
|║+0#0000001#ffd7ff255| |a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d| | +0#0000000#0000001
6+
|║+0#0000001#ffd7ff255| |f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s| @52| +0#0000000#a8a8a8255
7+
|╚+0#0000001#ffd7ff255|═@73
8+
|8+0#0000000#ffffff0| @73
9+
|9| @73
10+
@57|1|,|1| @10|T|o|p|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>1+0&#ffffff0| @73
2+
|2| @73
3+
|╔+0#0000001#ffd7ff255|═@73
4+
|║| |a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d| | +0#0000000#a8a8a8255
5+
|║+0#0000001#ffd7ff255| |f|a|s|d|f|a|s|d|f|a|s|d|f|a|s|d|f|a|s| @52| +0#0000000#0000001
6+
|║+0#0000001#ffd7ff255| |t+0&#e0e0e08|h|r|e@1| @65| +0&#ffd7ff255| +0#0000000#0000001
7+
|╚+0#0000001#ffd7ff255|═@73
8+
|8+0#0000000#ffffff0| @73
9+
|9| @73
10+
@57|1|,|1| @10|T|o|p|

src/testdir/test_popupwin.vim

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,38 @@ func Test_popup_close_with_mouse()
509509
call delete('XtestPopupClose')
510510
endfunction
511511

512+
func Test_popup_menu_wrap()
513+
CheckScreendump
514+
515+
let lines =<< trim END
516+
call setline(1, range(1, 20))
517+
call popup_create([
518+
\ 'one',
519+
\ 'asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfas',
520+
\ 'three',
521+
\ 'four',
522+
\ ], #{
523+
\ pos: "botleft",
524+
\ border: [],
525+
\ padding: [0,1,0,1],
526+
\ maxheight: 3,
527+
\ cursorline: 1,
528+
\ filter: 'popup_filter_menu',
529+
\ })
530+
END
531+
call writefile(lines, 'XtestPopupWrap')
532+
let buf = RunVimInTerminal('-S XtestPopupWrap', #{rows: 10})
533+
call VerifyScreenDump(buf, 'Test_popupwin_wrap_1', {})
534+
535+
call term_sendkeys(buf, "jj")
536+
call VerifyScreenDump(buf, 'Test_popupwin_wrap_2', {})
537+
538+
" clean up
539+
call term_sendkeys(buf, "\<Esc>")
540+
call StopVimInTerminal(buf)
541+
call delete('XtestPopupWrap')
542+
endfunction
543+
512544
func Test_popup_with_mask()
513545
CheckScreendump
514546

src/version.c

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

754754
static int included_patches[] =
755755
{ /* Add new patch number below this line */
756+
/**/
757+
2164,
756758
/**/
757759
2163,
758760
/**/

0 commit comments

Comments
 (0)