diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-12-03 11:51:54 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-12-03 11:51:54 +0000 |
commit | 1b73edd9ee40aec400f3611f59823cec5fd1c489 (patch) | |
tree | 055429e63a64891487e5563f8df66581996e4112 | |
parent | 8ffb7e051da74afef7264e1f25a7142f15aa1f60 (diff) |
patch 9.0.0998: "gk" may reset skipcol when not neededv9.0.0998
Problem: "gk" may reset skipcol when not needed.
Solution: Only reset skipcol if the cursor column is less.
-rw-r--r-- | src/move.c | 5 | ||||
-rw-r--r-- | src/testdir/test_scroll_opt.vim | 46 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 44 insertions, 9 deletions
diff --git a/src/move.c b/src/move.c index 14667f3279..d976697ec9 100644 --- a/src/move.c +++ b/src/move.c @@ -2343,7 +2343,7 @@ scroll_cursor_top(int min_scroll, int always) { /* * 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; @@ -2360,7 +2360,8 @@ scroll_cursor_top(int min_scroll, int always) check_topfill(curwin, FALSE); #endif // TODO: 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(); if (curwin->w_topline != old_topline || curwin->w_skipcol != old_skipcol diff --git a/src/testdir/test_scroll_opt.vim b/src/testdir/test_scroll_opt.vim index 96afce068f..6f8693ba73 100644 --- a/src/testdir/test_scroll_opt.vim +++ b/src/testdir/test_scroll_opt.vim @@ -359,6 +359,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 @@ -368,12 +374,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>" @@ -450,9 +450,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 diff --git a/src/version.c b/src/version.c index 682beb0874..da9b03a522 100644 --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 998, +/**/ 997, /**/ 996, |