Skip to content

Commit a112f2d

Browse files
committed
patch 8.1.1959: when using "firstline" in popup window text may jump
Problem: When using "firstline" in popup window text may jump when redrawing it. (Nick Jensen) Solution: Set 'scrolloff' to zero in a popup window. (closes #4882)
1 parent c330835 commit a112f2d

5 files changed

Lines changed: 37 additions & 11 deletions

File tree

src/popupwin.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,11 +1687,12 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
16871687
buf->b_p_swf = FALSE; // no swap file
16881688
buf->b_p_bl = FALSE; // unlisted buffer
16891689
buf->b_locked = TRUE;
1690-
wp->w_p_wrap = TRUE; // 'wrap' is default on
16911690

16921691
// Avoid that 'buftype' is reset when this buffer is entered.
16931692
buf->b_p_initialized = TRUE;
16941693
}
1694+
wp->w_p_wrap = TRUE; // 'wrap' is default on
1695+
wp->w_p_so = 0; // 'scrolloff' zero
16951696

16961697
if (tp != NULL)
16971698
{
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
>1+0&#ffffff0| @73
22
|2| @73
33
|3| @73
4-
|4| @31|f+0#0000001#ffd7ff255|o|u|r| @3| +0#0000000#ff404010| +0&#ffffff0@32
5-
|5| @31|f+0#0000001#ffd7ff255|i|v|e| @3| +0#0000000#4040ff13| +0&#ffffff0@32
6-
|6| @31|s+0#0000001#ffd7ff255|i|x| @4| +0#0000000#4040ff13| +0&#ffffff0@32
7-
|7| @31|s+0#0000001#ffd7ff255|e|v|e|n| @2| +0#0000000#ff404010| +0&#ffffff0@32
4+
|4| @31|t+0#0000001#ffd7ff255|h|r|e@1| @2| +0#0000000#ff404010| +0&#ffffff0@32
5+
|5| @31|f+0#0000001#ffd7ff255|o|u|r| @3| +0#0000000#4040ff13| +0&#ffffff0@32
6+
|6| @31|f+0#0000001#ffd7ff255|i|v|e| @3| +0#0000000#4040ff13| +0&#ffffff0@32
7+
|7| @31|s+0#0000001#ffd7ff255|i|x| @4| +0#0000000#ff404010| +0&#ffffff0@32
88
|8| @73
99
|9| @73
1010
|:|c|a|l@1| |S|c|r|o|l@1|U|p|(|)| @40|1|,|1| @10|T|o|p|
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
>1+0&#ffffff0| @73
22
|2| @73
33
|3| @73
4-
|4| @31|s+0#0000001#ffd7ff255|i|x| @4| +0#0000000#ff404010| +0&#ffffff0@32
5-
|5| @31|s+0#0000001#ffd7ff255|e|v|e|n| @2| +0#0000000#ff404010| +0&#ffffff0@32
6-
|6| @31|e+0#0000001#ffd7ff255|i|g|h|t| @2| +0#0000000#4040ff13| +0&#ffffff0@32
7-
|7| @31|n+0#0000001#ffd7ff255|i|n|e| @3| +0#0000000#4040ff13| +0&#ffffff0@32
4+
|4| @31|f+0#0000001#ffd7ff255|i|v|e| @3| +0#0000000#ff404010| +0&#ffffff0@32
5+
|5| @31|s+0#0000001#ffd7ff255|i|x| @4| +0#0000000#ff404010| +0&#ffffff0@32
6+
|6| @31|s+0#0000001#ffd7ff255|e|v|e|n| @2| +0#0000000#4040ff13| +0&#ffffff0@32
7+
|7| @31|e+0#0000001#ffd7ff255|i|g|h|t| @2| +0#0000000#4040ff13| +0&#ffffff0@32
88
|8| @73
99
|9| @73
1010
|:|c|a|l@1| |S|c|r|o|l@1|D|o|w|n|(|)| @38|1|,|1| @10|T|o|p|

src/testdir/test_popupwin.vim

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,24 @@ func Test_popup_firstline()
371371
call popup_close(winid)
372372
endfunc
373373

374+
func Test_popup_noscrolloff()
375+
set scrolloff=5
376+
let winid = popup_create(['xxx']->repeat(50), #{
377+
\ maxheight: 5,
378+
\ firstline: 11,
379+
\ })
380+
redraw
381+
call assert_equal(11, popup_getoptions(winid).firstline)
382+
call assert_equal(11, popup_getpos(winid).firstline)
383+
384+
call popup_setoptions(winid, #{firstline: 0})
385+
call win_execute(winid, "normal! \<c-y>")
386+
call assert_equal(0, popup_getoptions(winid).firstline)
387+
call assert_equal(10, popup_getpos(winid).firstline)
388+
389+
call popup_close(winid)
390+
endfunc
391+
374392
func Test_popup_drag()
375393
CheckScreendump
376394

@@ -1019,14 +1037,18 @@ func Test_popup_option_values()
10191037
" global/buffer-local
10201038
setlocal path=/there
10211039
" global/window-local
1022-
setlocal scrolloff=9
1040+
setlocal statusline=2
10231041

10241042
let winid = popup_create('hello', {})
10251043
call assert_equal(0, getwinvar(winid, '&number'))
10261044
call assert_equal(1, getwinvar(winid, '&wrap'))
10271045
call assert_equal('', getwinvar(winid, '&omnifunc'))
10281046
call assert_equal(&g:path, getwinvar(winid, '&path'))
1029-
call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff'))
1047+
call assert_equal(&g:statusline, getwinvar(winid, '&statusline'))
1048+
1049+
" 'scrolloff' is reset to zero
1050+
call assert_equal(5, &scrolloff)
1051+
call assert_equal(0, getwinvar(winid, '&scrolloff'))
10301052

10311053
call popup_close(winid)
10321054
bwipe
@@ -1713,6 +1735,7 @@ func Test_popup_scrollbar()
17131735
call VerifyScreenDump(buf, 'Test_popupwin_scroll_4', {})
17141736

17151737
call term_sendkeys(buf, ":call popup_setoptions(winid, #{scrollbarhighlight: 'ScrollBar', thumbhighlight: 'ScrollThumb', firstline: 5})\<CR>")
1738+
" this scrolls two lines (half the window height)
17161739
call term_sendkeys(buf, ":call ScrollUp()\<CR>")
17171740
call VerifyScreenDump(buf, 'Test_popupwin_scroll_5', {})
17181741

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1959,
764766
/**/
765767
1958,
766768
/**/

0 commit comments

Comments
 (0)