aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/move.c4
-rw-r--r--test/functional/legacy/scroll_opt_spec.lua25
-rw-r--r--test/old/testdir/test_scroll_opt.vim17
3 files changed, 45 insertions, 1 deletions
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 7a4e98adc5..7cc368a36b 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -1816,7 +1816,9 @@ void scroll_cursor_top(int min_scroll, int always)
}
}
check_topfill(curwin, false);
- if (curwin->w_topline == curwin->w_cursor.lnum) {
+ if (curwin->w_topline != old_topline) {
+ reset_skipcol(curwin);
+ } else if (curwin->w_topline == curwin->w_cursor.lnum) {
validate_virtcol();
if (curwin->w_skipcol >= curwin->w_virtcol) {
// TODO(vim): if the line doesn't fit may optimize w_skipcol instead
diff --git a/test/functional/legacy/scroll_opt_spec.lua b/test/functional/legacy/scroll_opt_spec.lua
index 5b4bfb3caa..d4e4702f5e 100644
--- a/test/functional/legacy/scroll_opt_spec.lua
+++ b/test/functional/legacy/scroll_opt_spec.lua
@@ -982,6 +982,31 @@ describe('smoothscroll', function()
]])
end)
+ -- oldtest: Test_smoothscroll_cursor_top()
+ it('resets skipcol when scrolling cursor to top', function()
+ screen:try_resize(40, 12)
+ exec([[
+ set smoothscroll scrolloff=2
+ new | 11resize | wincmd j
+ call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4'])
+ exe "norm G3\<C-E>k"
+ ]])
+ screen:expect([[
+ |
+ [No Name] |
+ line1 |
+ line2 |
+ ^line3line3line3line3line3line3line3line3|
+ line3line3line3line3line3line3line3line3|
+ line3line3line3line3 |
+ line4 |
+ ~ |
+ ~ |
+ [No Name] [+] |
+ |
+ ]])
+ end)
+
it("works with virt_lines above and below", function()
screen:try_resize(55, 7)
exec([=[
diff --git a/test/old/testdir/test_scroll_opt.vim b/test/old/testdir/test_scroll_opt.vim
index 80f73ba5d9..f428e77579 100644
--- a/test/old/testdir/test_scroll_opt.vim
+++ b/test/old/testdir/test_scroll_opt.vim
@@ -912,4 +912,21 @@ func Test_smoothscroll_zero_width_scroll_cursor_bot()
call StopVimInTerminal(buf)
endfunc
+" scroll_cursor_top() should reset skipcol when it changes topline
+func Test_smoothscroll_cursor_top()
+ CheckScreendump
+
+ let lines =<< trim END
+ set smoothscroll scrolloff=2
+ new | 11resize | wincmd j
+ call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4'])
+ exe "norm G3\<C-E>k"
+ END
+ call writefile(lines, 'XSmoothScrollCursorTop', 'D')
+ let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCursorTop', #{rows: 12, cols:40})
+ call VerifyScreenDump(buf, 'Test_smoothscroll_cursor_top', {})
+
+ call StopVimInTerminal(buf)
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab