aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/move.c45
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;