From 4147302f4be3fe8a5dae3f20a336477cb5f507a4 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Tue, 26 Mar 2024 19:06:39 +0100 Subject: vim-patch:9.1.0211: page-wise scrolling does not support smooth-scrolling Problem: Page-wise scrolling with Ctrl-F/Ctrl-B implements it's own logic to change the topline and cursor. In doing so, skipcol is not handled properly for 'smoothscroll', and virtual lines. Solution: Re-use the logic from Ctrl-E/Ctrl-Y while staying backward compatible as much as possible. https://github.com/vim/vim/commit/b9f5b95b7bec2414a5a96010514702d99afea18e --- test/functional/legacy/scroll_opt_spec.lua | 2 +- test/old/testdir/test_diffmode.vim | 40 ++++++++++++++++-------------- test/old/testdir/test_edit.vim | 40 +++++++++++++++--------------- test/old/testdir/test_normal.vim | 32 +++++++++++++++--------- test/old/testdir/test_scroll_opt.vim | 24 +++++++++++++++++- 5 files changed, 86 insertions(+), 52 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/scroll_opt_spec.lua b/test/functional/legacy/scroll_opt_spec.lua index 78028f2f44..c00993f5f7 100644 --- a/test/functional/legacy/scroll_opt_spec.lua +++ b/test/functional/legacy/scroll_opt_spec.lua @@ -740,7 +740,7 @@ describe('smoothscroll', function() | ]]) exec("call setline(92, 'a'->repeat(100))") - feed('G') + feed('G') -- cursor is not placed below window screen:expect([[ {1:<<<}aaaaaaaaaaaaaaaaa | diff --git a/test/old/testdir/test_diffmode.vim b/test/old/testdir/test_diffmode.vim index c1a63a6f88..3e7eabf8f5 100644 --- a/test/old/testdir/test_diffmode.vim +++ b/test/old/testdir/test_diffmode.vim @@ -1632,34 +1632,38 @@ endfunc func Test_diff_scroll_many_filler() 20new vnew - call setline(1, ['^^^', '^^^', '$$$', '$$$']) + call setline(1, range(1, 40)) diffthis setlocal scrolloff=0 wincmd p - call setline(1, ['^^^', '^^^'] + repeat(['###'], 41) + ['$$$', '$$$']) + call setline(1, range(1, 20)->reverse() + ['###']->repeat(41) + range(21, 40)->reverse()) diffthis setlocal scrolloff=0 wincmd p redraw " Note: need a redraw after each scroll, otherwise the test always passes. - normal! G - redraw - call assert_equal(3, winsaveview().topline) - call assert_equal(18, winsaveview().topfill) - exe "normal! \" - redraw - call assert_equal(3, winsaveview().topline) - call assert_equal(19, winsaveview().topfill) - exe "normal! \" - redraw - call assert_equal(2, winsaveview().topline) - call assert_equal(0, winsaveview().topfill) - exe "normal! \" - redraw - call assert_equal(1, winsaveview().topline) - call assert_equal(0, winsaveview().topfill) + for _ in range(2) + normal! G + redraw + call assert_equal(40, winsaveview().topline) + call assert_equal(19, winsaveview().topfill) + exe "normal! \" + redraw + call assert_equal(22, winsaveview().topline) + call assert_equal(0, winsaveview().topfill) + exe "normal! \" + redraw + call assert_equal(4, winsaveview().topline) + call assert_equal(0, winsaveview().topfill) + exe "normal! \" + redraw + call assert_equal(1, winsaveview().topline) + call assert_equal(0, winsaveview().topfill) + set smoothscroll + endfor + set smoothscroll& bwipe! bwipe! endfunc diff --git a/test/old/testdir/test_edit.vim b/test/old/testdir/test_edit.vim index 8281b3d495..2d4314a276 100644 --- a/test/old/testdir/test_edit.vim +++ b/test/old/testdir/test_edit.vim @@ -1312,15 +1312,15 @@ func Test_edit_PAGEUP_PAGEDOWN() call feedkeys("i\\", 'tnix') call assert_equal([0, 30, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 29, 1, 0], getpos('.')) + call assert_equal([0, 30, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 21, 1, 0], getpos('.')) + call assert_equal([0, 23, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 13, 1, 0], getpos('.')) + call assert_equal([0, 15, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 5, 1, 0], getpos('.')) + call assert_equal([0, 10, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 5, 11, 0], getpos('.')) + call assert_equal([0, 10, 11, 0], getpos('.')) " is the same as " is the same as call cursor(1, 1) @@ -1335,28 +1335,28 @@ func Test_edit_PAGEUP_PAGEDOWN() call feedkeys("i\\", 'tnix') call assert_equal([0, 30, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 29, 1, 0], getpos('.')) + call assert_equal([0, 30, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 21, 1, 0], getpos('.')) + call assert_equal([0, 23, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 13, 1, 0], getpos('.')) + call assert_equal([0, 15, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 5, 1, 0], getpos('.')) + call assert_equal([0, 10, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 5, 11, 0], getpos('.')) + call assert_equal([0, 10, 11, 0], getpos('.')) set nostartofline call cursor(30, 11) norm! zt call feedkeys("A\\", 'tnix') - call assert_equal([0, 29, 11, 0], getpos('.')) + call assert_equal([0, 30, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 21, 11, 0], getpos('.')) + call assert_equal([0, 23, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 13, 11, 0], getpos('.')) + call assert_equal([0, 15, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 5, 11, 0], getpos('.')) + call assert_equal([0, 10, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 5, 11, 0], getpos('.')) + call assert_equal([0, 10, 11, 0], getpos('.')) call cursor(1, 1) call feedkeys("A\\", 'tnix') call assert_equal([0, 9, 11, 0], getpos('.')) @@ -1373,15 +1373,15 @@ func Test_edit_PAGEUP_PAGEDOWN() call cursor(30, 11) norm! zt call feedkeys("A\\", 'tnix') - call assert_equal([0, 29, 11, 0], getpos('.')) + call assert_equal([0, 30, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 21, 11, 0], getpos('.')) + call assert_equal([0, 23, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 13, 11, 0], getpos('.')) + call assert_equal([0, 15, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 5, 11, 0], getpos('.')) + call assert_equal([0, 10, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 5, 11, 0], getpos('.')) + call assert_equal([0, 10, 11, 0], getpos('.')) call cursor(1, 1) call feedkeys("A\\", 'tnix') call assert_equal([0, 9, 11, 0], getpos('.')) diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index d31ae488d9..644a632413 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -131,7 +131,7 @@ func Test_normal01_keymodel() call assert_equal([0, 1, 1, 0], getpos("'<")) call assert_equal([0, 3, 1, 0], getpos("'>")) call feedkeys("Gz\8|\y", 'xt') - call assert_equal([0, 2, 1, 0], getpos("'<")) + call assert_equal([0, 3, 1, 0], getpos("'<")) call assert_equal([0, 3, 8, 0], getpos("'>")) " Test for and call cursor(2, 12) @@ -915,12 +915,10 @@ func Test_normal14_page() set scrolloff=0 100 exe "norm! $\" - call assert_equal('92', getline('.')) call assert_equal([0, 92, 1, 0, 1], getcurpos()) 100 set nostartofline exe "norm! $\" - call assert_equal('92', getline('.')) call assert_equal([0, 92, 2, 0, v:maxcol], getcurpos()) " cleanup set startofline @@ -3825,11 +3823,11 @@ func Test_normal_vert_scroll_longline() call assert_equal(11, line('.')) call assert_equal(1, winline()) exe "normal \" - call assert_equal(10, line('.')) - call assert_equal(3, winline()) + call assert_equal(11, line('.')) + call assert_equal(9, winline()) exe "normal \\" call assert_equal(5, line('.')) - call assert_equal(5, winline()) + call assert_equal(1, winline()) bwipe! endfunc @@ -4182,20 +4180,30 @@ func Test_normal34_zet_large() norm! z9765405999999999999 endfunc -" Test for { and } paragraph movements in a single line -func Test_brace_single_line() - let text =<< trim [DATA] - foobar one two three - [DATA] +" Test for { and } paragraph movements and Ctrl-B in buffer with a single line +func Test_single_line_scroll() + CheckFeature textprop new - call setline(1, text) + call setline(1, ['foobar one two three']) + let vt = 'virt_above' + call prop_type_add(vt, {'highlight': 'IncSearch'}) + call prop_add(1, 0, {'type': vt, 'text': '---', 'text_align': 'above'}) 1 norm! 0} call assert_equal([0, 1, 20, 0], getpos('.')) norm! { call assert_equal([0, 1, 1, 0], getpos('.')) + + " Ctrl-B scrolls up with hidden "above" virtual text. + set smoothscroll + exe "normal \" + call assert_notequal(0, winsaveview().skipcol) + exe "normal \" + call assert_equal(0, winsaveview().skipcol) + + set smoothscroll& bw! endfunc diff --git a/test/old/testdir/test_scroll_opt.vim b/test/old/testdir/test_scroll_opt.vim index 8130f7a1ac..ebfed77214 100644 --- a/test/old/testdir/test_scroll_opt.vim +++ b/test/old/testdir/test_scroll_opt.vim @@ -832,7 +832,7 @@ func Test_smoothscroll_eob() call VerifyScreenDump(buf, 'Test_smooth_eob_1', {}) " cursor is not placed below window - call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\\G") + call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\\\G") call VerifyScreenDump(buf, 'Test_smooth_eob_2', {}) call StopVimInTerminal(buf) @@ -1001,4 +1001,26 @@ func Test_smoothscroll_textoff_small_winwidth() set smoothscroll& number& endfunc +func Test_smoothscroll_page() + set smoothscroll + + 10split | 40vsplit + call setline(1, 'abcde '->repeat(150)) + + exe "norm! \" + call assert_equal(320, winsaveview().skipcol) + exe "norm! \" + call assert_equal(640, winsaveview().skipcol) + exe "norm! \" + call assert_equal(880, winsaveview().skipcol) + exe "norm! \" + call assert_equal(560, winsaveview().skipcol) + exe "norm! \" + call assert_equal(240, winsaveview().skipcol) + exe "norm! \" + call assert_equal(0, winsaveview().skipcol) + + set smoothscroll& +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 2f638c0ac6275bebacd12671481642fa43d7ba10 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 28 Mar 2024 10:20:45 +0100 Subject: vim-patch:9.1.0215: Half-page scrolling does not support smooth-scrolling Problem: Page-wise scrolling with Ctrl-D/Ctrl-U implements it's own logic to change the topline and cursor. More logic than necessary for scrolling with Ctrl-F/Ctrl-B was removed in patch 9.1.0211. Solution: Re-use the logic from Ctrl-E/Ctrl-Y/Ctrl-F/Ctrl-B while staying backward compatible as much as possible. Restore some of the logic that determined how many lines will be scrolled (Luuk van Baal) https://github.com/vim/vim/commit/5a2e3ec9ac72b6e644fea4ebba7e632498296e2f --- test/functional/legacy/matchparen_spec.lua | 2 +- test/old/testdir/test_edit.vim | 32 +++++++++++++++--------------- test/old/testdir/test_normal.vim | 26 +++++++++++++++--------- test/old/testdir/test_scroll_opt.vim | 29 +++++++++++++++++++++++---- 4 files changed, 59 insertions(+), 30 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/matchparen_spec.lua b/test/functional/legacy/matchparen_spec.lua index 7b3f7bd424..adbf15d2e3 100644 --- a/test/functional/legacy/matchparen_spec.lua +++ b/test/functional/legacy/matchparen_spec.lua @@ -19,7 +19,7 @@ describe('matchparen', function() call cursor(5, 1) ]]) - feed('V') + feed('V3j') screen:expect([[ {17:{} | {17:}} | diff --git a/test/old/testdir/test_edit.vim b/test/old/testdir/test_edit.vim index 2d4314a276..ba084442d1 100644 --- a/test/old/testdir/test_edit.vim +++ b/test/old/testdir/test_edit.vim @@ -1312,15 +1312,15 @@ func Test_edit_PAGEUP_PAGEDOWN() call feedkeys("i\\", 'tnix') call assert_equal([0, 30, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 30, 1, 0], getpos('.')) + call assert_equal([0, 29, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 23, 1, 0], getpos('.')) + call assert_equal([0, 21, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 15, 1, 0], getpos('.')) + call assert_equal([0, 13, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') call assert_equal([0, 10, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 10, 11, 0], getpos('.')) + call assert_equal([0, 2, 11, 0], getpos('.')) " is the same as " is the same as call cursor(1, 1) @@ -1335,28 +1335,28 @@ func Test_edit_PAGEUP_PAGEDOWN() call feedkeys("i\\", 'tnix') call assert_equal([0, 30, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 30, 1, 0], getpos('.')) + call assert_equal([0, 29, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 23, 1, 0], getpos('.')) + call assert_equal([0, 21, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 15, 1, 0], getpos('.')) + call assert_equal([0, 13, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') call assert_equal([0, 10, 1, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 10, 11, 0], getpos('.')) + call assert_equal([0, 2, 11, 0], getpos('.')) set nostartofline call cursor(30, 11) norm! zt call feedkeys("A\\", 'tnix') - call assert_equal([0, 30, 11, 0], getpos('.')) + call assert_equal([0, 29, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 23, 11, 0], getpos('.')) + call assert_equal([0, 21, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 15, 11, 0], getpos('.')) + call assert_equal([0, 13, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') call assert_equal([0, 10, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 10, 11, 0], getpos('.')) + call assert_equal([0, 2, 11, 0], getpos('.')) call cursor(1, 1) call feedkeys("A\\", 'tnix') call assert_equal([0, 9, 11, 0], getpos('.')) @@ -1373,15 +1373,15 @@ func Test_edit_PAGEUP_PAGEDOWN() call cursor(30, 11) norm! zt call feedkeys("A\\", 'tnix') - call assert_equal([0, 30, 11, 0], getpos('.')) + call assert_equal([0, 29, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 23, 11, 0], getpos('.')) + call assert_equal([0, 21, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 15, 11, 0], getpos('.')) + call assert_equal([0, 13, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') call assert_equal([0, 10, 11, 0], getpos('.')) call feedkeys("A\\", 'tnix') - call assert_equal([0, 10, 11, 0], getpos('.')) + call assert_equal([0, 2, 11, 0], getpos('.')) call cursor(1, 1) call feedkeys("A\\", 'tnix') call assert_equal([0, 9, 11, 0], getpos('.')) diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index 644a632413..937f18aa69 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -1283,9 +1283,13 @@ func Test_vert_scroll_cmds() exe "normal \" call assert_equal(46, line('.')) exe "normal \" - call assert_equal(36, line('.')) + call assert_equal(36, line('w0')) + call assert_equal(46, line('.')) exe "normal \" - call assert_equal(10, line('.')) + call assert_equal(1, line('w0')) + call assert_equal(40, line('.')) + exe "normal \" + call assert_equal(30, line('.')) exe "normal \" call assert_equal(1, line('.')) set scroll& @@ -1306,9 +1310,8 @@ func Test_vert_scroll_cmds() call assert_equal(50, line('.')) call assert_equal(100, line('w$')) normal z. - let lnum = winline() exe "normal \" - call assert_equal(lnum, winline()) + call assert_equal(1, winline()) call assert_equal(50, line('.')) normal zt exe "normal \" @@ -3077,7 +3080,8 @@ func Test_normal42_halfpage() call assert_equal(2, &scroll) set scroll=5 exe "norm! \" - call assert_equal('3', getline('.')) + call assert_equal('3', getline('w0')) + call assert_equal('8', getline('.')) 1 set scrolloff=5 exe "norm! \" @@ -3823,11 +3827,11 @@ func Test_normal_vert_scroll_longline() call assert_equal(11, line('.')) call assert_equal(1, winline()) exe "normal \" - call assert_equal(11, line('.')) - call assert_equal(9, winline()) + call assert_equal(10, line('.')) + call assert_equal(10, winline()) exe "normal \\" call assert_equal(5, line('.')) - call assert_equal(1, winline()) + call assert_equal(5, winline()) bwipe! endfunc @@ -4196,12 +4200,16 @@ func Test_single_line_scroll() norm! { call assert_equal([0, 1, 1, 0], getpos('.')) - " Ctrl-B scrolls up with hidden "above" virtual text. + " Ctrl-B/Ctrl-U scroll up with hidden "above" virtual text. set smoothscroll exe "normal \" call assert_notequal(0, winsaveview().skipcol) exe "normal \" call assert_equal(0, winsaveview().skipcol) + exe "normal \" + call assert_notequal(0, winsaveview().skipcol) + exe "normal \" + call assert_equal(0, winsaveview().skipcol) set smoothscroll& bw! diff --git a/test/old/testdir/test_scroll_opt.vim b/test/old/testdir/test_scroll_opt.vim index ebfed77214..fbc714d9cc 100644 --- a/test/old/testdir/test_scroll_opt.vim +++ b/test/old/testdir/test_scroll_opt.vim @@ -1008,18 +1008,39 @@ func Test_smoothscroll_page() call setline(1, 'abcde '->repeat(150)) exe "norm! \" - call assert_equal(320, winsaveview().skipcol) + call assert_equal(400, winsaveview().skipcol) exe "norm! \" - call assert_equal(640, winsaveview().skipcol) + call assert_equal(800, winsaveview().skipcol) exe "norm! \" call assert_equal(880, winsaveview().skipcol) exe "norm! \" - call assert_equal(560, winsaveview().skipcol) + call assert_equal(480, winsaveview().skipcol) exe "norm! \" - call assert_equal(240, winsaveview().skipcol) + call assert_equal(80, winsaveview().skipcol) exe "norm! \" call assert_equal(0, winsaveview().skipcol) + exe "norm! \" + call assert_equal(200, winsaveview().skipcol) + exe "norm! \" + call assert_equal(400, winsaveview().skipcol) + exe "norm! \" + call assert_equal(600, winsaveview().skipcol) + exe "norm! \" + call assert_equal(800, winsaveview().skipcol) + exe "norm! \" + call assert_equal(880, winsaveview().skipcol) + exe "norm! \" + call assert_equal(680, winsaveview().skipcol) + exe "norm! \" + call assert_equal(480, winsaveview().skipcol) + exe "norm! \" + call assert_equal(280, winsaveview().skipcol) + exe "norm! \" + call assert_equal(80, winsaveview().skipcol) + exe "norm! \" + call assert_equal(0, winsaveview().skipcol) + set smoothscroll& endfunc -- cgit