aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/move.c5
-rw-r--r--test/old/testdir/test_scroll_opt.vim46
2 files changed, 42 insertions, 9 deletions
diff --git a/src/nvim/move.c b/src/nvim/move.c
index abe908cfa0..2bae811e6d 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -1776,7 +1776,7 @@ void scroll_cursor_top(int min_scroll, int always)
scroll_cursor_halfway(false, false);
} else {
// If "always" is false, only adjust topline to a lower value, higher
- // value may happen with wrapping lines
+ // value may happen with wrapping lines.
if (new_topline < curwin->w_topline || always) {
curwin->w_topline = new_topline;
}
@@ -1792,7 +1792,8 @@ void scroll_cursor_top(int min_scroll, int always)
}
check_topfill(curwin, false);
// TODO(vim): if the line doesn't fit may optimize w_skipcol
- if (curwin->w_topline == curwin->w_cursor.lnum) {
+ if (curwin->w_topline == curwin->w_cursor.lnum
+ && curwin->w_skipcol >= curwin->w_cursor.col) {
reset_skipcol(curwin);
}
if (curwin->w_topline != old_topline
diff --git a/test/old/testdir/test_scroll_opt.vim b/test/old/testdir/test_scroll_opt.vim
index 3707e211fc..c8d0f51384 100644
--- a/test/old/testdir/test_scroll_opt.vim
+++ b/test/old/testdir/test_scroll_opt.vim
@@ -376,6 +376,12 @@ func Test_smoothscroll_long_line_showbreak()
call StopVimInTerminal(buf)
endfunc
+func s:check_col_calc(win_col, win_line, buf_col)
+ call assert_equal(a:win_col, wincol())
+ call assert_equal(a:win_line, winline())
+ call assert_equal(a:buf_col, col('.'))
+endfunc
+
" Test that if the current cursor is on a smooth scrolled line, we correctly
" reposition it. Also check that we don't miscalculate the values by checking
" the consistency between wincol() and col('.') as they are calculated
@@ -385,12 +391,6 @@ func Test_smoothscroll_cursor_position()
setl smoothscroll wrap
call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
- func s:check_col_calc(win_col, win_line, buf_col)
- call assert_equal(a:win_col, wincol())
- call assert_equal(a:win_line, winline())
- call assert_equal(a:buf_col, col('.'))
- endfunc
-
call s:check_col_calc(1, 1, 1)
exe "normal \<C-E>"
@@ -467,9 +467,41 @@ func Test_smoothscroll_cursor_position()
call s:check_col_calc(1, 3, 37)
normal gg
- bwipeout!
+ bwipe!
endfunc
+func Test_smoothscroll_cursor_scrolloff()
+ call NewWindow(10, 20)
+ setl smoothscroll wrap
+ setl scrolloff=3
+
+ " 120 chars are 6 screen lines
+ call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
+ call setline(2, "below")
+
+ call s:check_col_calc(1, 1, 1)
+
+ " CTRL-E shows "<<<DEFG...", cursor move four lines down
+ exe "normal \<C-E>"
+ call s:check_col_calc(1, 4, 81)
+
+ " cursor on start of second line, "gk" moves into first line, skipcol doesn't
+ " change
+ exe "normal G0gk"
+ call s:check_col_calc(1, 5, 101)
+
+ " move cursor left one window width worth, scrolls one screen line
+ exe "normal 20h"
+ call s:check_col_calc(1, 5, 81)
+
+ " move cursor left one window width worth, scrolls one screen line
+ exe "normal 20h"
+ call s:check_col_calc(1, 4, 61)
+
+ bwipe!
+endfunc
+
+
" Test that mouse picking is still accurate when we have smooth scrolled lines
func Test_smoothscroll_mouse_pos()
CheckNotGui