@@ -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 {
0 commit comments