mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.1.2240: popup window width changes when scrolling
Problem: Popup window width changes when scrolling. Solution: Also adjust maxwidth when applying minwidth and there is a scrollbar. Fix off-by-one error. (closes #5162)
This commit is contained in:
@@ -1201,6 +1201,7 @@ popup_adjust_position(win_T *wp)
|
||||
allow_adjust_left = FALSE;
|
||||
maxwidth = wp->w_maxwidth;
|
||||
}
|
||||
minwidth = wp->w_minwidth;
|
||||
|
||||
// start at the desired first line
|
||||
if (wp->w_firstline > 0)
|
||||
@@ -1270,18 +1271,19 @@ popup_adjust_position(win_T *wp)
|
||||
if (wp->w_maxwidth > 0 && wp->w_width > wp->w_maxwidth)
|
||||
wp->w_width = wp->w_maxwidth;
|
||||
}
|
||||
// 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)
|
||||
+ 1 + wrapped > wp->w_maxheight)
|
||||
break;
|
||||
|
||||
if (wp->w_firstline < 0)
|
||||
--lnum;
|
||||
else
|
||||
++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;
|
||||
}
|
||||
|
||||
if (wp->w_firstline < 0)
|
||||
@@ -1293,11 +1295,13 @@ popup_adjust_position(win_T *wp)
|
||||
{
|
||||
++right_extra;
|
||||
++extra_width;
|
||||
if (used_maxwidth)
|
||||
maxwidth -= 2; // try to show the scrollbar
|
||||
// make space for the scrollbar if needed, when lines wrap and when
|
||||
// applying minwidth
|
||||
if (maxwidth + right_extra >= maxspace
|
||||
&& (used_maxwidth || (minwidth > 0 && wp->w_width < minwidth)))
|
||||
maxwidth -= wp->w_popup_padding[1] + 1;
|
||||
}
|
||||
|
||||
minwidth = wp->w_minwidth;
|
||||
if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL)
|
||||
{
|
||||
int title_len = vim_strsize(wp->w_popup_title) + 2 - extra_width;
|
||||
|
@@ -2,12 +2,12 @@
|
||||
|#|i|n|c|l|u|d|e| |"|X|h|e|a|d|e|r|.|h|"| @54
|
||||
|t|h|r|e@1| @69
|
||||
|f|o|u|r| @70
|
||||
|f|i|v|e| @27|╔+0#0000001#ffd7ff255| |X|t|a|g|f|i|l|e| |═@30|X
|
||||
|s+0#0000000#ffffff0|i|x| @28|║+0#0000001#ffd7ff255|2|7| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|s+0#0000000#ffffff0|e|v|e|n| @26|║+0#0000001#ffd7ff255|t|h|i|s| |i|s| |a|n|o|t|h|e|r| |p|l|a|c|e| @18| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|f+0#0000000#ffffff0|i|n|d| |t|h|e|w|o|r|d| |s|o|m|e|w|h|e|r|e| @9|║+0#0000001#ffd7ff255|2|9| @37| +0#0000000#0000001|║+0#0000001#ffd7ff255
|
||||
|n+0#0000000#ffffff0|i|n|e| @27|║+0#0000001#ffd7ff255|3|0| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|t+0#0000000#ffffff0|h|i|s| |i|s| |a|n|o|t|h|e|r| |w|o|r|d| @11|╚+0#0000001#ffd7ff255|═@40|⇲
|
||||
|f|i|v|e| @28|╔+0#0000001#ffd7ff255| |X|t|a|g|f|i|l|e| |═@29|X
|
||||
|s+0#0000000#ffffff0|i|x| @29|║+0#0000001#ffd7ff255|2|7| @36| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|s+0#0000000#ffffff0|e|v|e|n| @27|║+0#0000001#ffd7ff255|t|h|i|s| |i|s| |a|n|o|t|h|e|r| |p|l|a|c|e| @17| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|f+0#0000000#ffffff0|i|n|d| |t|h|e|w|o|r|d| |s|o|m|e|w|h|e|r|e| @10|║+0#0000001#ffd7ff255|2|9| @36| +0#0000000#0000001|║+0#0000001#ffd7ff255
|
||||
|n+0#0000000#ffffff0|i|n|e| @28|║+0#0000001#ffd7ff255|3|0| @36| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|t+0#0000000#ffffff0|h|i|s| |i|s| |a|n|o|t|h|e|r| |w|o|r|d| @12|╚+0#0000001#ffd7ff255|═@39|⇲
|
||||
|v+0#0000000#ffffff0|e|r|y| |l|o|n|g| |l|i|n|e| |w|h|e|r|e| |t|h|e| |w|o|r|d| |i|s| |a|l|s|o| >a|n|o|t|h|e|r| @29
|
||||
|~+0#4040ff13&| @73
|
||||
|~| @73
|
||||
|
@@ -2,12 +2,12 @@
|
||||
|#|i|n|c|l|u|d|e| |"|X|h|e|a|d|e|r|.|h|"| @54
|
||||
|t|h|r|e@1| @69
|
||||
|f|o|u|r| @70
|
||||
|f|i|v|e| @27|╔+0#0000001#ffd7ff255| |t|e|s|t|d|i|r|/|X|t|a|g|f|i|l|e| |═@22|X
|
||||
|s+0#0000000#ffffff0|i|x| @28|║+0#0000001#ffd7ff255|2|7| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|s+0#0000000#ffffff0|e|v|e|n| @26|║+0#0000001#ffd7ff255|t|h|i|s| |i|s| |a|n|o|t|h|e|r| |p|l|a|c|e| @18| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|f+0#0000000#ffffff0|i|n|d| |t|h|e|w|o|r|d| |s|o|m|e|w|h|e|r|e| @9|║+0#0000001#ffd7ff255|2|9| @37| +0#0000000#0000001|║+0#0000001#ffd7ff255
|
||||
|n+0#0000000#ffffff0|i|n|e| @27|║+0#0000001#ffd7ff255|3|0| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|t+0#0000000#ffffff0|h|i|s| |i|s| |a|n|o|t|h|e|r| |w|o|r|d| @11|╚+0#0000001#ffd7ff255|═@40|⇲
|
||||
|f|i|v|e| @28|╔+0#0000001#ffd7ff255| |t|e|s|t|d|i|r|/|X|t|a|g|f|i|l|e| |═@21|X
|
||||
|s+0#0000000#ffffff0|i|x| @29|║+0#0000001#ffd7ff255|2|7| @36| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|s+0#0000000#ffffff0|e|v|e|n| @27|║+0#0000001#ffd7ff255|t|h|i|s| |i|s| |a|n|o|t|h|e|r| |p|l|a|c|e| @17| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|f+0#0000000#ffffff0|i|n|d| |t|h|e|w|o|r|d| |s|o|m|e|w|h|e|r|e| @10|║+0#0000001#ffd7ff255|2|9| @36| +0#0000000#0000001|║+0#0000001#ffd7ff255
|
||||
|n+0#0000000#ffffff0|i|n|e| @28|║+0#0000001#ffd7ff255|3|0| @36| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|t+0#0000000#ffffff0|h|i|s| |i|s| |a|n|o|t|h|e|r| |w|o|r|d| @12|╚+0#0000001#ffd7ff255|═@39|⇲
|
||||
|v+0#0000000#ffffff0|e|r|y| |l|o|n|g| |l|i|n|e| |w|h|e|r|e| |t|h|e| |w|o|r|d| |i|s| |a|l|s|o| >a|n|o|t|h|e|r| @29
|
||||
|~+0#4040ff13&| @73
|
||||
|~| @73
|
||||
|
@@ -2,12 +2,12 @@
|
||||
|#|i|n|c|l|u|d|e| |"|X|h|e|a|d|e|r|.|h|"| @54
|
||||
|t|h|r|e@1| @69
|
||||
|f|o|u|r| @70
|
||||
|f|i|v|e| @27|╔+0#0000001#ffd7ff255| |X|t|a|g|f|i|l|e| |═@30|X
|
||||
|s+0#0000000#ffffff0|i|x| @28|║+0#0000001#ffd7ff255|2|0| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|s+0#0000000#ffffff0|e|v|e|n| @26|║+0#0000001#ffd7ff255|t|h|e|w|o|r|d| |i|s| |h|e|r|e| @24| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|f+0#0000000#ffffff0|i|n|d| |t|h|e|w|o|r|d| |s|o|m|e|w|h|e|r|e| @9|║+0#0000001#ffd7ff255|2@1| @37| +0#0000000#0000001|║+0#0000001#ffd7ff255
|
||||
|n+0#0000000#ffffff0|i|n|e| @27|║+0#0000001#ffd7ff255|2|3| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|t+0#0000000#ffffff0|h|i|s| |i|s| |a|n|o|t|h|e|r| |w|o|r|d| @11|╚+0#0000001#ffd7ff255|═@40|⇲
|
||||
|f|i|v|e| @28|╔+0#0000001#ffd7ff255| |X|t|a|g|f|i|l|e| |═@29|X
|
||||
|s+0#0000000#ffffff0|i|x| @29|║+0#0000001#ffd7ff255|2|0| @36| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|s+0#0000000#ffffff0|e|v|e|n| @27|║+0#0000001#ffd7ff255|t|h|e|w|o|r|d| |i|s| |h|e|r|e| @23| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|f+0#0000000#ffffff0|i|n|d| |t|h|e|w|o|r|d| |s|o|m|e|w|h|e|r|e| @10|║+0#0000001#ffd7ff255|2@1| @36| +0#0000000#0000001|║+0#0000001#ffd7ff255
|
||||
|n+0#0000000#ffffff0|i|n|e| @28|║+0#0000001#ffd7ff255|2|3| @36| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|t+0#0000000#ffffff0|h|i|s| |i|s| |a|n|o|t|h|e|r| |w|o|r|d| @12|╚+0#0000001#ffd7ff255|═@39|⇲
|
||||
|v+0#0000000#ffffff0|e|r|y| |l|o|n|g| |l|i|n|e| |w|h|e|r|e| |t|h|e| |w|o|r|d| |i|s| |a|l|s|o| >a|n|o|t|h|e|r| @29
|
||||
|~+0#4040ff13&| @73
|
||||
|~| @73
|
||||
|
@@ -2,12 +2,12 @@
|
||||
|#|i|n|c|l|u|d|e| |"|X|h|e|a|d|e|r|.|h|"| @54
|
||||
|t|h|r|e@1| @69
|
||||
|f|o|u|r| @70
|
||||
|f|i|v|e| @27|╔+0#0000001#ffd7ff255| |X|h|e|a|d|e|r|.|h| |═@29|X
|
||||
|s+0#0000000#ffffff0|i|x| @28|║+0#0000001#ffd7ff255|1+0#e000002&|0| +0#0000001&@37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|s+0#0000000#ffffff0|e|v|e|n| @26|║+0#0000001#ffd7ff255|s|e|a|r|c|h|e|d| |w|o|r|d| |i|s| |h|e|r|e| @18| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|f+0#0000000#ffffff0|i|n|d| |t|h|e|w|o|r|d| |s|o|m|e|w|h|e|r|e| @9|║+0#0000001#ffd7ff255|1+0#e000002&|2| +0#0000001&@37| +0#0000000#0000001|║+0#0000001#ffd7ff255
|
||||
|n+0#0000000#ffffff0|i|n|e| @27|║+0#0000001#ffd7ff255|1+0#e000002&|3| +0#0000001&@37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|t+0#0000000#ffffff0|h|i|s| |i|s| |a|n|o|t|h|e|r| |w|o|r|d| @11|╚+0#0000001#ffd7ff255|═@40|⇲
|
||||
|f|i|v|e| @28|╔+0#0000001#ffd7ff255| |X|h|e|a|d|e|r|.|h| |═@28|X
|
||||
|s+0#0000000#ffffff0|i|x| @29|║+0#0000001#ffd7ff255|1+0#e000002&|0| +0#0000001&@36| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|s+0#0000000#ffffff0|e|v|e|n| @27|║+0#0000001#ffd7ff255|s|e|a|r|c|h|e|d| |w|o|r|d| |i|s| |h|e|r|e| @17| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|f+0#0000000#ffffff0|i|n|d| |t|h|e|w|o|r|d| |s|o|m|e|w|h|e|r|e| @10|║+0#0000001#ffd7ff255|1+0#e000002&|2| +0#0000001&@36| +0#0000000#0000001|║+0#0000001#ffd7ff255
|
||||
|n+0#0000000#ffffff0|i|n|e| @28|║+0#0000001#ffd7ff255|1+0#e000002&|3| +0#0000001&@36| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|
||||
|t+0#0000000#ffffff0|h|i|s| |i|s| |a|n|o|t|h|e|r| |w|o|r|d| @12|╚+0#0000001#ffd7ff255|═@39|⇲
|
||||
|v+0#0000000#ffffff0|e|r|y| |l|o|n|g| |l|i|n|e| |w|h|e|r|e| |t|h|e| |w|o|r|d| |i|s| |a|l|s|o| >a|n|o|t|h|e|r| @29
|
||||
|~+0#4040ff13&| @73
|
||||
|~| @73
|
||||
|
10
src/testdir/dumps/Test_popupwin_scroll_11.dump
Normal file
10
src/testdir/dumps/Test_popupwin_scroll_11.dump
Normal file
@@ -0,0 +1,10 @@
|
||||
>1+0&#ffffff0| @73
|
||||
|2| @73
|
||||
|3| @73
|
||||
|4| @20|1+0#0000001#ffd7ff255| @28| +0#0000000#0000001| +0&#ffffff0@21
|
||||
|5| @20|2+0#0000001#ffd7ff255| @28| +0#0000000#0000001| +0&#ffffff0@21
|
||||
|6| @20|3+0#0000001#ffd7ff255| @28| +0#0000000#a8a8a8255| +0&#ffffff0@21
|
||||
|7| @20|4+0#0000001#ffd7ff255| @28| +0#0000000#a8a8a8255| +0&#ffffff0@21
|
||||
|8| @73
|
||||
|9| @73
|
||||
|:|c|a|l@1| |P|o|p|u|p|S|c|r|o|l@1|(|)| @37|1|,|1| @10|T|o|p|
|
10
src/testdir/dumps/Test_popupwin_scroll_12.dump
Normal file
10
src/testdir/dumps/Test_popupwin_scroll_12.dump
Normal file
@@ -0,0 +1,10 @@
|
||||
>1+0&#ffffff0| @73
|
||||
|2| @73
|
||||
|3| @73
|
||||
|4| @20|2+0#0000001#ffd7ff255| @28| +0#0000000#a8a8a8255| +0&#ffffff0@21
|
||||
|5| @20|3+0#0000001#ffd7ff255| @28| +0#0000000#0000001| +0&#ffffff0@21
|
||||
|6| @20|4+0#0000001#ffd7ff255| @28| +0#0000000#0000001| +0&#ffffff0@21
|
||||
|7| @20|l+0#0000001#ffd7ff255|o|n|g| |l|i|n|e| |l|o|n|g| |l|i|n|e| |l|o|n|g| |l|i|n|e| | +0#0000000#a8a8a8255| +0&#ffffff0@21
|
||||
|8| @73
|
||||
|9| @73
|
||||
|:|c|a|l@1| |P|o|p|u|p|S|c|r|o|l@1|(|)| @37|1|,|1| @10|T|o|p|
|
@@ -1764,6 +1764,42 @@ func Test_popup_scrollbar()
|
||||
call popup_setoptions(g:winid, #{border: [], close: 'button'})
|
||||
call feedkeys("\<F5>\<LeftMouse>", "xt")
|
||||
endfunc
|
||||
func Popup_filter(winid, key)
|
||||
if a:key == 'j'
|
||||
let line = popup_getoptions(a:winid).firstline
|
||||
let nlines = line('$', a:winid)
|
||||
let newline = line < nlines ? (line + 1) : nlines
|
||||
call popup_setoptions(a:winid, #{firstline: newline})
|
||||
return v:true
|
||||
elseif a:key == 'x'
|
||||
call popup_close(a:winid)
|
||||
return v:true
|
||||
endif
|
||||
endfunc
|
||||
|
||||
func PopupScroll()
|
||||
call popup_clear()
|
||||
let text =<< trim END
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
long line long line long line long line long line long line
|
||||
long line long line long line long line long line long line
|
||||
long line long line long line long line long line long line
|
||||
END
|
||||
call popup_create(text, #{
|
||||
\ minwidth: 30,
|
||||
\ maxwidth: 30,
|
||||
\ minheight: 4,
|
||||
\ maxheight: 4,
|
||||
\ firstline: 1,
|
||||
\ wrap: v:true,
|
||||
\ scrollbar: v:true,
|
||||
\ mapping: v:false,
|
||||
\ filter: funcref('Popup_filter')
|
||||
\ })
|
||||
endfunc
|
||||
map <silent> <F3> :call test_setmouse(5, 36)<CR>
|
||||
map <silent> <F4> :call test_setmouse(4, 42)<CR>
|
||||
map <silent> <F5> :call test_setmouse(7, 42)<CR>
|
||||
@@ -1811,6 +1847,15 @@ func Test_popup_scrollbar()
|
||||
call term_sendkeys(buf, ":\<CR>")
|
||||
call VerifyScreenDump(buf, 'Test_popupwin_scroll_10', {})
|
||||
|
||||
" check size with non-wrapping lines
|
||||
call term_sendkeys(buf, ":call PopupScroll()\<CR>")
|
||||
call VerifyScreenDump(buf, 'Test_popupwin_scroll_11', {})
|
||||
|
||||
" check size with wrapping lines
|
||||
call term_sendkeys(buf, "j")
|
||||
call VerifyScreenDump(buf, 'Test_popupwin_scroll_12', {})
|
||||
call term_sendkeys(buf, "x")
|
||||
|
||||
" clean up
|
||||
call StopVimInTerminal(buf)
|
||||
call delete('XtestPopupScroll')
|
||||
|
@@ -741,6 +741,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
2240,
|
||||
/**/
|
||||
2239,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user