To: vim_dev@googlegroups.com Subject: Patch 8.2.1406 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1406 Problem: Popupwindow lacks scrollbar if no "maxheight" is used. Solution: Compute the max height depending on the position. (closes #6664) Files: src/popupwin.c, src/testdir/test_popupwin.vim, src/testdir/dumps/Test_popupwin_toohigh_1.dump, src/testdir/dumps/Test_popupwin_toohigh_2.dump *** ../vim-8.2.1405/src/popupwin.c 2020-07-27 22:40:20.694572378 +0200 --- src/popupwin.c 2020-08-09 16:15:15.743733573 +0200 *************** *** 1130,1135 **** --- 1130,1136 ---- int org_leftcol = wp->w_leftcol; int org_leftoff = wp->w_popup_leftoff; int minwidth, minheight; + int maxheight = Rows; int wantline = wp->w_wantline; // adjusted for textprop int wantcol = wp->w_wantcol; // adjusted for textprop int use_wantcol = wantcol != 0; *************** *** 1277,1282 **** --- 1278,1286 ---- } #endif + if (wp->w_maxheight > 0) + maxheight = wp->w_maxheight; + // start at the desired first line if (wp->w_firstline > 0) wp->w_topline = wp->w_firstline; *************** *** 1353,1363 **** ++lnum; // do not use the width of lines we're not going to show ! if (wp->w_maxheight > 0 && (wp->w_firstline >= 0 ? lnum - wp->w_topline : wp->w_buffer->b_ml.ml_line_count - lnum) ! + wrapped >= wp->w_maxheight) break; } --- 1357,1367 ---- ++lnum; // do not use the width of lines we're not going to show ! if (maxheight > 0 && (wp->w_firstline >= 0 ? lnum - wp->w_topline : wp->w_buffer->b_ml.ml_line_count - lnum) ! + wrapped >= maxheight) break; } *************** *** 1449,1461 **** + 1 + wrapped; if (minheight > 0 && wp->w_height < minheight) wp->w_height = minheight; ! if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight) ! wp->w_height = wp->w_maxheight; w_height_before_limit = wp->w_height; if (wp->w_height > Rows - wp->w_winrow) wp->w_height = Rows - wp->w_winrow; - if (wp->w_height != org_height) - win_comp_scroll(wp); if (center_vert) { --- 1453,1463 ---- + 1 + wrapped; if (minheight > 0 && wp->w_height < minheight) wp->w_height = minheight; ! if (maxheight > 0 && wp->w_height > maxheight) ! wp->w_height = maxheight; w_height_before_limit = wp->w_height; if (wp->w_height > Rows - wp->w_winrow) wp->w_height = Rows - wp->w_winrow; if (center_vert) { *************** *** 1477,1485 **** --- 1479,1499 ---- wp->w_height = wantline - extra_height; } else + { // Not enough space and more space on the other side: make top // aligned. wp->w_winrow = (wantline < 0 ? 0 : wantline) + 1; + if (wp->w_winrow + wp->w_height + extra_height >= Rows) + { + wp->w_height = Rows - wp->w_winrow - extra_height; + if (wp->w_want_scrollbar + #ifdef FEAT_TERMINAL + && wp->w_buffer->b_term == NULL + #endif + ) + wp->w_has_scrollbar = TRUE; + } + } } else if (wp->w_popup_pos == POPPOS_TOPRIGHT || wp->w_popup_pos == POPPOS_TOPLEFT) *************** *** 1501,1511 **** --- 1515,1529 ---- else wp->w_winrow = wantline - 1; } + // make sure w_window is valid if (wp->w_winrow >= Rows) wp->w_winrow = Rows - 1; else if (wp->w_winrow < 0) wp->w_winrow = 0; + if (wp->w_height != org_height) + win_comp_scroll(wp); + wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer); if (win_valid(wp->w_popup_prop_win)) { *** ../vim-8.2.1405/src/testdir/test_popupwin.vim 2020-07-30 20:08:46.840890218 +0200 --- src/testdir/test_popupwin.vim 2020-08-09 16:31:53.911821627 +0200 *************** *** 2144,2149 **** --- 2144,2179 ---- call delete('XtestPopupScroll') endfunc + func Test_popup_too_high_scrollbar() + CheckScreendump + + let lines =<< trim END + call setline(1, range(1, 20)->map({i, v -> repeat(v, 10)})) + set scrolloff=0 + func ShowPopup() + let winid = popup_atcursor(['one', 'two', 'three', 'four', 'five', + \ 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve'], #{ + \ minwidth: 8, + \ border: [], + \ }) + endfunc + normal 3G$ + call ShowPopup() + END + call writefile(lines, 'XtestPopupToohigh') + let buf = RunVimInTerminal('-S XtestPopupToohigh', #{rows: 10}) + call VerifyScreenDump(buf, 'Test_popupwin_toohigh_1', {}) + + call term_sendkeys(buf, ":call popup_clear()\") + call term_sendkeys(buf, "8G$") + call term_sendkeys(buf, ":call ShowPopup()\") + call VerifyScreenDump(buf, 'Test_popupwin_toohigh_2', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('XtestPopupToohigh') + endfunc + func Test_popup_fitting_scrollbar() " this was causing a crash, divide by zero let winid = popup_create([ *** ../vim-8.2.1405/src/testdir/dumps/Test_popupwin_toohigh_1.dump 2020-08-09 16:36:26.026589763 +0200 --- src/testdir/dumps/Test_popupwin_toohigh_1.dump 2020-08-09 16:32:05.655757800 +0200 *************** *** 0 **** --- 1,10 ---- + |1+0&#ffffff0@9| @64 + |2@9| @64 + |3@8>3| @64 + |4@8|╔+0#0000001#ffd7ff255|═@8|╗| +0#0000000#ffffff0@54 + |5@8|║+0#0000001#ffd7ff255|o|n|e| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54 + |6@8|║+0#0000001#ffd7ff255|t|w|o| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54 + |7@8|║+0#0000001#ffd7ff255|t|h|r|e@1| @2| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54 + |8@8|║+0#0000001#ffd7ff255|f|o|u|r| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54 + |9@8|║+0#0000001#ffd7ff255|f|i|v|e| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54 + @9|╚+0#0000001#ffd7ff255|═@8|╝| +0#0000000#ffffff0@36|3|,|1|0| @9|T|o|p| *** ../vim-8.2.1405/src/testdir/dumps/Test_popupwin_toohigh_2.dump 2020-08-09 16:36:26.030589749 +0200 --- src/testdir/dumps/Test_popupwin_toohigh_2.dump 2020-08-09 16:32:06.711752121 +0200 *************** *** 0 **** --- 1,10 ---- + |1+0&#ffffff0@8|╔+0#0000001#ffd7ff255|═@8|╗| +0#0000000#ffffff0@54 + |2@8|║+0#0000001#ffd7ff255|o|n|e| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54 + |3@8|║+0#0000001#ffd7ff255|t|w|o| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54 + |4@8|║+0#0000001#ffd7ff255|t|h|r|e@1| @2| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54 + |5@8|║+0#0000001#ffd7ff255|f|o|u|r| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54 + |6@8|║+0#0000001#ffd7ff255|f|i|v|e| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54 + |7@8|╚+0#0000001#ffd7ff255|═@8|╝| +0#0000000#ffffff0@54 + |8@8>8| @64 + |9@9| @64 + |:|c|a|l@1| |S|h|o|w|P|o|p|u|p|(|)| @39|8|,|1|0| @9|T|o|p| *** ../vim-8.2.1405/src/version.c 2020-08-09 15:24:52.165418739 +0200 --- src/version.c 2020-08-09 15:59:35.621292473 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1406, /**/ -- hundred-and-one symptoms of being an internet addict: 164. You got out to buy software, instead of going out for a beer. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///