Skip to content

Commit a1b9b0c

Browse files
committed
patch 8.2.1406: popupwindow lacks scrollbar if no "maxheight" is used
Problem: Popupwindow lacks scrollbar if no "maxheight" is used. Solution: Compute the max height depending on the position. (closes #6664)
1 parent a7cc9e6 commit a1b9b0c

5 files changed

Lines changed: 76 additions & 6 deletions

File tree

src/popupwin.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ popup_adjust_position(win_T *wp)
11301130
int org_leftcol = wp->w_leftcol;
11311131
int org_leftoff = wp->w_popup_leftoff;
11321132
int minwidth, minheight;
1133+
int maxheight = Rows;
11331134
int wantline = wp->w_wantline; // adjusted for textprop
11341135
int wantcol = wp->w_wantcol; // adjusted for textprop
11351136
int use_wantcol = wantcol != 0;
@@ -1277,6 +1278,9 @@ popup_adjust_position(win_T *wp)
12771278
}
12781279
#endif
12791280

1281+
if (wp->w_maxheight > 0)
1282+
maxheight = wp->w_maxheight;
1283+
12801284
// start at the desired first line
12811285
if (wp->w_firstline > 0)
12821286
wp->w_topline = wp->w_firstline;
@@ -1353,11 +1357,11 @@ popup_adjust_position(win_T *wp)
13531357
++lnum;
13541358

13551359
// do not use the width of lines we're not going to show
1356-
if (wp->w_maxheight > 0
1360+
if (maxheight > 0
13571361
&& (wp->w_firstline >= 0
13581362
? lnum - wp->w_topline
13591363
: wp->w_buffer->b_ml.ml_line_count - lnum)
1360-
+ wrapped >= wp->w_maxheight)
1364+
+ wrapped >= maxheight)
13611365
break;
13621366
}
13631367

@@ -1449,13 +1453,11 @@ popup_adjust_position(win_T *wp)
14491453
+ 1 + wrapped;
14501454
if (minheight > 0 && wp->w_height < minheight)
14511455
wp->w_height = minheight;
1452-
if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight)
1453-
wp->w_height = wp->w_maxheight;
1456+
if (maxheight > 0 && wp->w_height > maxheight)
1457+
wp->w_height = maxheight;
14541458
w_height_before_limit = wp->w_height;
14551459
if (wp->w_height > Rows - wp->w_winrow)
14561460
wp->w_height = Rows - wp->w_winrow;
1457-
if (wp->w_height != org_height)
1458-
win_comp_scroll(wp);
14591461

14601462
if (center_vert)
14611463
{
@@ -1477,9 +1479,21 @@ popup_adjust_position(win_T *wp)
14771479
wp->w_height = wantline - extra_height;
14781480
}
14791481
else
1482+
{
14801483
// Not enough space and more space on the other side: make top
14811484
// aligned.
14821485
wp->w_winrow = (wantline < 0 ? 0 : wantline) + 1;
1486+
if (wp->w_winrow + wp->w_height + extra_height >= Rows)
1487+
{
1488+
wp->w_height = Rows - wp->w_winrow - extra_height;
1489+
if (wp->w_want_scrollbar
1490+
#ifdef FEAT_TERMINAL
1491+
&& wp->w_buffer->b_term == NULL
1492+
#endif
1493+
)
1494+
wp->w_has_scrollbar = TRUE;
1495+
}
1496+
}
14831497
}
14841498
else if (wp->w_popup_pos == POPPOS_TOPRIGHT
14851499
|| wp->w_popup_pos == POPPOS_TOPLEFT)
@@ -1501,11 +1515,15 @@ popup_adjust_position(win_T *wp)
15011515
else
15021516
wp->w_winrow = wantline - 1;
15031517
}
1518+
// make sure w_window is valid
15041519
if (wp->w_winrow >= Rows)
15051520
wp->w_winrow = Rows - 1;
15061521
else if (wp->w_winrow < 0)
15071522
wp->w_winrow = 0;
15081523

1524+
if (wp->w_height != org_height)
1525+
win_comp_scroll(wp);
1526+
15091527
wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer);
15101528
if (win_valid(wp->w_popup_prop_win))
15111529
{
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|1+0&#ffffff0@9| @64
2+
|2@9| @64
3+
|3@8>3| @64
4+
|4@8|╔+0#0000001#ffd7ff255|═@8|╗| +0#0000000#ffffff0@54
5+
|5@8|║+0#0000001#ffd7ff255|o|n|e| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
6+
|6@8|║+0#0000001#ffd7ff255|t|w|o| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
7+
|7@8|║+0#0000001#ffd7ff255|t|h|r|e@1| @2| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
8+
|8@8|║+0#0000001#ffd7ff255|f|o|u|r| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
9+
|9@8|║+0#0000001#ffd7ff255|f|i|v|e| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
10+
@9|╚+0#0000001#ffd7ff255|═@8|╝| +0#0000000#ffffff0@36|3|,|1|0| @9|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@8|╔+0#0000001#ffd7ff255|═@8|╗| +0#0000000#ffffff0@54
2+
|2@8|║+0#0000001#ffd7ff255|o|n|e| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
3+
|3@8|║+0#0000001#ffd7ff255|t|w|o| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
4+
|4@8|║+0#0000001#ffd7ff255|t|h|r|e@1| @2| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
5+
|5@8|║+0#0000001#ffd7ff255|f|o|u|r| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
6+
|6@8|║+0#0000001#ffd7ff255|f|i|v|e| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
7+
|7@8|╚+0#0000001#ffd7ff255|═@8|╝| +0#0000000#ffffff0@54
8+
|8@8>8| @64
9+
|9@9| @64
10+
|:|c|a|l@1| |S|h|o|w|P|o|p|u|p|(|)| @39|8|,|1|0| @9|T|o|p|

src/testdir/test_popupwin.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,36 @@ func Test_popup_scrollbar()
21442144
call delete('XtestPopupScroll')
21452145
endfunc
21462146

2147+
func Test_popup_too_high_scrollbar()
2148+
CheckScreendump
2149+
2150+
let lines =<< trim END
2151+
call setline(1, range(1, 20)->map({i, v -> repeat(v, 10)}))
2152+
set scrolloff=0
2153+
func ShowPopup()
2154+
let winid = popup_atcursor(['one', 'two', 'three', 'four', 'five',
2155+
\ 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve'], #{
2156+
\ minwidth: 8,
2157+
\ border: [],
2158+
\ })
2159+
endfunc
2160+
normal 3G$
2161+
call ShowPopup()
2162+
END
2163+
call writefile(lines, 'XtestPopupToohigh')
2164+
let buf = RunVimInTerminal('-S XtestPopupToohigh', #{rows: 10})
2165+
call VerifyScreenDump(buf, 'Test_popupwin_toohigh_1', {})
2166+
2167+
call term_sendkeys(buf, ":call popup_clear()\<CR>")
2168+
call term_sendkeys(buf, "8G$")
2169+
call term_sendkeys(buf, ":call ShowPopup()\<CR>")
2170+
call VerifyScreenDump(buf, 'Test_popupwin_toohigh_2', {})
2171+
2172+
" clean up
2173+
call StopVimInTerminal(buf)
2174+
call delete('XtestPopupToohigh')
2175+
endfunc
2176+
21472177
func Test_popup_fitting_scrollbar()
21482178
" this was causing a crash, divide by zero
21492179
let winid = popup_create([

src/version.c

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

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1406,
757759
/**/
758760
1405,
759761
/**/

0 commit comments

Comments
 (0)