diff options
author | Luuk van Baal <luukvbaal@gmail.com> | 2023-04-27 18:35:25 +0200 |
---|---|---|
committer | Luuk van Baal <luukvbaal@gmail.com> | 2023-05-02 13:11:47 +0200 |
commit | 3621604029119a8806da006eb0468cf65e23b980 (patch) | |
tree | 68f3cb7f23359dcd6a2285c82abe5c0e7c1638e4 /src | |
parent | 0bcf2a6382eca34a827b678987e03874001d9610 (diff) | |
download | rneovim-3621604029119a8806da006eb0468cf65e23b980.tar.gz rneovim-3621604029119a8806da006eb0468cf65e23b980.tar.bz2 rneovim-3621604029119a8806da006eb0468cf65e23b980.zip |
vim-patch:9.0.0900: cursor moves too far with 'smoothscroll'
Problem: Cursor moves too far with 'smoothscroll'.
Solution: Only move as far as really needed. (Yee Cheng Chin, closes vim/vim#11504)
https://github.com/vim/vim/commit/81ba26e9de24ca6b1c05b6ec03e53b21793f1a4b
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/move.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/src/nvim/move.c b/src/nvim/move.c index 8113331c62..b0a4a3848a 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -164,6 +164,22 @@ static void redraw_for_cursorcolumn(win_T *wp) } } +/// Calculates how much overlap the smoothscroll marker "<<<" overlaps with +/// buffer text for curwin. +/// Parameter "extra2" should be the padding on the 2nd line, not the first +/// line. +/// Returns the number of columns of overlap with buffer text, excluding the +/// extra padding on the ledge. +static int smoothscroll_marker_overlap(win_T *wp, int extra2) +{ + // We don't draw the <<< marker when in showbreak mode, thus no need to + // account for it. See grid_put_linebuf(). + if (*get_showbreak_value(wp) != NUL) { + return 0; + } + return extra2 > 3 ? 0 : 3 - extra2; +} + /// Set wp->s_skipcol to zero and redraw later if needed. static void reset_skipcol(win_T *wp) { @@ -239,10 +255,12 @@ void update_topline(win_T *wp) } else if (wp->w_skipcol > 0 && wp->w_cursor.lnum == wp->w_topline) { colnr_T vcol; - // check the cursor position is visible. Add 3 for the ">>>" - // displayed in the top-left. + // Check that the cursor position is visible. Add columns for the + // smoothscroll marker "<<<" displayed in the top-left if needed. getvvcol(wp, &wp->w_cursor, &vcol, NULL, NULL); - if (wp->w_skipcol + 3 >= vcol) { + int smoothscroll_overlap = smoothscroll_marker_overlap(wp, + win_col_off(wp) - win_col_off2(wp)); + if (wp->w_skipcol + smoothscroll_overlap > vcol) { check_topline = true; } } @@ -1387,12 +1405,21 @@ bool scrollup(long line_count, int byfold) } if (curwin->w_cursor.lnum == curwin->w_topline && do_sms && curwin->w_skipcol > 0) { - int width1 = curwin->w_width - curwin_col_off(); - int width2 = width1 + curwin_col_off2(); + int col_off = curwin_col_off(); + int col_off2 = curwin_col_off2(); + + int width1 = curwin->w_width - col_off; + int width2 = width1 + col_off2; + int extra2 = col_off - col_off2; long so = get_scrolloff_value(curwin); long scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2; int space_cols = (curwin->w_height - 1) * width2; + // If we have non-zero scrolloff, just ignore the <<< marker as we are + // going past it anyway. + int smoothscroll_overlap = scrolloff_cols != 0 ? 0 : + smoothscroll_marker_overlap(curwin, extra2); + // Make sure the cursor is in a visible part of the line, taking // 'scrolloff' into account, but using screen lines. // If there are not enough screen lines put the cursor in the middle. @@ -1400,13 +1427,13 @@ bool scrollup(long line_count, int byfold) scrolloff_cols = space_cols / 2; } validate_virtcol(); - if (curwin->w_virtcol < curwin->w_skipcol + 3 + scrolloff_cols) { + if (curwin->w_virtcol < curwin->w_skipcol + smoothscroll_overlap + scrolloff_cols) { colnr_T col = curwin->w_virtcol; if (col < width1) { col += width1; } - while (col < curwin->w_skipcol + 3 + scrolloff_cols) { + while (col < curwin->w_skipcol + smoothscroll_overlap + scrolloff_cols) { col += width2; } curwin->w_curswant = col; @@ -2180,9 +2207,9 @@ void cursor_correct(void) curwin->w_viewport_invalid = true; } -// move screen 'count' pages up or down and update screen +// Move screen "count" pages up or down and update screen. // -// return FAIL for failure, OK otherwise +// Return FAIL for failure, OK otherwise. int onepage(Direction dir, long count) { long n; |