Repository: neovim/neovim
File: src/nvim/move.c (C)

Code before:
}

/// Scroll "count" lines with 'smoothscroll' in direction "dir". Return true
/// when scrolling happened. Adjust "curscount" for scrolling different amount
/// of lines when 'smoothscroll' is disabled.
static bool scroll_with_sms(Direction dir, int count, int *curscount)
{
  int prev_sms = curwin->w_p_sms;
  colnr_T prev_skipcol = curwin->w_skipcol;
  linenr_T prev_topline = curwin->w_topline;
  int prev_topfill = curwin->w_topfill;

  curwin->w_p_sms = true;
  scroll_redraw(dir == FORWARD, count);

  // Not actually smoothscrolling but ended up with partially visible line.
  // Continue scrolling until skipcol is zero.
  if (!prev_sms && curwin->w_skipcol > 0) {
    int fixdir = dir;
    // Reverse the scroll direction when topline already changed. One line
    // extra for scrolling backward so that consuming skipcol is symmetric.
    if (labs(curwin->w_topline - prev_topline) > (dir == BACKWARD)) {
      fixdir = dir * -1;
    }

    int width1 = curwin->w_width - win_col_off(curwin);
    int width2 = width1 + win_col_off2(curwin);
    count = 1 + (curwin->w_skipcol - width1) / width2;
    if (fixdir == FORWARD) {
      count = 2 + (linetabsize_eol(curwin, curwin->w_topline)
                   - curwin->w_skipcol - width1) / width2;
    }
    scroll_redraw(fixdir == FORWARD, count);
    *curscount += count * (fixdir == dir ? 1 : -1);
  }
  curwin->w_p_sms = prev_sms;

  return curwin->w_topline == prev_topline
         && curwin->w_topfill == prev_topfill
         && curwin->w_skipcol == prev_skipcol;
}

/// Move screen "count" (half) pages up ("dir" is BACKWARD) or down ("dir" is
/// FORWARD) and update the screen. Handle moving the cursor and not scrolling
/// to reveal end of buffer lines for half-page scrolling with CTRL-D and CTRL-U.
///
/// @return  FAIL for failure, OK otherwise.
int pagescroll(Direction dir, int count, bool half)
{
  int nochange = true;
  int buflen = curbuf->b_ml.ml_line_count;

Review comment (suggestion):
```suggestion
    int width1 = curwin->w_view_width - win_col_off(curwin);
```

Code after:
}

/// Scroll "count" lines with 'smoothscroll' in direction "dir". Return true
/// when scrolling happened. Adjust "curscount" for scrolling different amount
/// of lines when 'smoothscroll' is disabled.
static bool scroll_with_sms(Direction dir, int count, int *curscount)
{
  int prev_sms = curwin->w_p_sms;
  colnr_T prev_skipcol = curwin->w_skipcol;
  linenr_T prev_topline = curwin->w_topline;
  int prev_topfill = curwin->w_topfill;

  curwin->w_p_sms = true;
  scroll_redraw(dir == FORWARD, count);

  // Not actually smoothscrolling but ended up with partially visible line.
  // Continue scrolling until skipcol is zero.
  if (!prev_sms && curwin->w_skipcol > 0) {
    int fixdir = dir;
    // Reverse the scroll direction when topline already changed. One line
    // extra for scrolling backward so that consuming skipcol is symmetric.
    if (labs(curwin->w_topline - prev_topline) > (dir == BACKWARD)) {
      fixdir = dir * -1;
    }

    int width1 = curwin->w_view_width - win_col_off(curwin);
    int width2 = width1 + win_col_off2(curwin);
    count = 1 + (curwin->w_skipcol - width1) / width2;
    if (fixdir == FORWARD) {
      count = 2 + (linetabsize_eol(curwin, curwin->w_topline)
                   - curwin->w_skipcol - width1) / width2;
    }
    scroll_redraw(fixdir == FORWARD, count);
    *curscount += count * (fixdir == dir ? 1 : -1);
  }
  curwin->w_p_sms = prev_sms;

  return curwin->w_topline == prev_topline
         && curwin->w_topfill == prev_topfill
         && curwin->w_skipcol == prev_skipcol;
}

/// Move screen "count" (half) pages up ("dir" is BACKWARD) or down ("dir" is
/// FORWARD) and update the screen. Handle moving the cursor and not scrolling
/// to reveal end of buffer lines for half-page scrolling with CTRL-D and CTRL-U.
///
/// @return  FAIL for failure, OK otherwise.
int pagescroll(Direction dir, int count, bool half)
{
  int nochange = true;
  int buflen = curbuf->b_ml.ml_line_count;