From 27abf5c81b83b245186cf6e605ca30a45ea46f76 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Thu, 15 May 2025 10:01:34 +0200 Subject: [PATCH] vim-patch:9.1.1388: Scrolling one line too far with 'nosmoothscroll' page scrolling (#34023) Problem: One-off error in "count" to make "w_skipcol" zero with 'nosmoothscroll' page scrolling when last virtual line in a buffer line is exactly the entire window width. (Hirohito Higashi) Solution: Properly compute the smallest integer value necessary to make "w_skipcol" zero (Luuk van Baal) https://github.com/vim/vim/commit/c6c72d165c90e94eee1d9107d82fb180ed138190 (cherry picked from commit f87b6230f12419ecc64bc304fabb6c41913dafe4) --- src/nvim/move.c | 6 +++--- test/old/testdir/test_normal.vim | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/nvim/move.c b/src/nvim/move.c index f6b34911f7..22a07818bf 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -2427,10 +2427,10 @@ static bool scroll_with_sms(Direction dir, int count, int *curscount) int width1 = curwin->w_width_inner - win_col_off(curwin); int width2 = width1 + win_col_off2(curwin); - count = 1 + (curwin->w_skipcol - width1) / width2; + count = 1 + (curwin->w_skipcol - width1 - 1) / width2; if (fixdir == FORWARD) { - count = 2 + (linetabsize_eol(curwin, curwin->w_topline) - - curwin->w_skipcol - width1) / width2; + count = 1 + (linetabsize_eol(curwin, curwin->w_topline) + - curwin->w_skipcol - width1 + width2 - 1) / width2; } scroll_redraw(fixdir == FORWARD, count); *curscount += count * (fixdir == dir ? 1 : -1); diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index 38ab6965a3..858d235233 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -4348,4 +4348,21 @@ func Test_scroll_longline_benchmark() bwipe! endfunc +" Test Ctrl-B with 'nosmoothscroll' not stuck with line exactly window width. +func Test_scroll_longline_winwidth() + 10new + call setline(1, ['']->repeat(20) + ['A'->repeat(20 * winwidth(0))] + ['']->repeat(20)) + exe "normal! G3\" + call assert_equal(22, line('w0')) + exe "normal! \" + call assert_equal(21, line('w0')) + exe "normal! \" + call assert_equal(11, line('w0')) + exe "normal! \" + call assert_equal(3, line('w0')) + exe "normal! \" + call assert_equal(1, line('w0')) + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab nofoldenable