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

Code before:
  // TODO(bfredl): this is due to the call in curs_columns(). We really don't want to
  // fiddle with the screen outside of update_screen() like this.
  int checked_width = MIN(grid->cols - col, wp->w_view_width);
  int checked_height = MIN(grid->rows - row_off, wp->w_view_height);

  // No lines are being moved, just draw over the entire area
  if (row + abs(line_count) >= checked_height) {
    return;
  }

  if (line_count < 0) {
    grid_del_lines(grid, row + row_off, -line_count,
                   checked_height + row_off, col, checked_width);
  } else {
    grid_ins_lines(grid, row + row_off, line_count,
                   checked_height + row_off, col, checked_width);
  }
}

/// Clear lines near the end of the window and mark the unused lines with "c1".
/// When "draw_margin" is true, then draw the sign/fold/number columns.
void win_draw_end(win_T *wp, schar_T c1, bool draw_margin, int startrow, int endrow, hlf_T hl)
{
  assert(hl >= 0 && hl < HLF_COUNT);
  for (int row = startrow; row < endrow; row++) {
    grid_line_start(&wp->w_grid, row, wp->w_view_width);

    int n = 0;
    if (draw_margin) {
      // draw the fold column
      int fdc = MAX(0, compute_foldcolumn(wp, 0));
      n = grid_line_fill(n, n + fdc, schar_from_ascii(' '), win_hl_attr(wp, HLF_FC));

      // draw the sign column
      n = grid_line_fill(n, n + wp->w_scwidth * SIGN_WIDTH, schar_from_ascii(' '),
                         win_hl_attr(wp, HLF_SC));

      // draw the number column
      if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) == NULL) {
        int width = number_width(wp) + 1;
        n = grid_line_fill(n, n + width, schar_from_ascii(' '), win_hl_attr(wp, HLF_N));
      }
    }

    int attr = win_hl_attr(wp, (int)hl);

    if (n < wp->w_view_width) {
      grid_line_put_schar(n, c1, attr);
      n++;
    }


Review comment (suggestion):
but if this is the **only** callsite which truly is changed I'd rather wrap the grid_line_fill/put calls right here with `MIN(foo, width)` and/or if statements, than changing the signature of `grid_line_start()` (which affects code which just wants to draw with already correct column args in every other place)

Code after:
  // TODO(bfredl): this is due to the call in curs_columns(). We really don't want to
  // fiddle with the screen outside of update_screen() like this.
  int checked_width = MIN(grid->cols - col, wp->w_view_width);
  int checked_height = MIN(grid->rows - row_off, wp->w_view_height);

  // No lines are being moved, just draw over the entire area
  if (row + abs(line_count) >= checked_height) {
    return;
  }

  if (line_count < 0) {
    grid_del_lines(grid, row + row_off, -line_count,
                   checked_height + row_off, col, checked_width);
  } else {
    grid_ins_lines(grid, row + row_off, line_count,
                   checked_height + row_off, col, checked_width);
  }
}

/// Clear lines near the end of the window and mark the unused lines with "c1".
/// When "draw_margin" is true, then draw the sign/fold/number columns.
void win_draw_end(win_T *wp, schar_T c1, bool draw_margin, int startrow, int endrow, hlf_T hl)
{
  assert(hl >= 0 && hl < HLF_COUNT);
  const int view_width = wp->w_view_width;
  const int fdc = compute_foldcolumn(wp, 0);
  const int scwidth = wp->w_scwidth;

  for (int row = startrow; row < endrow; row++) {
    grid_line_start(&wp->w_grid, row);

    int n = 0;
    if (draw_margin) {
      // draw the fold column
      if (fdc > 0) {
        n = grid_line_fill(n, MIN(view_width, n + fdc),
                           schar_from_ascii(' '), win_hl_attr(wp, HLF_FC));
      }

      // draw the sign column
      if (scwidth > 0) {
        n = grid_line_fill(n, MIN(view_width, n + scwidth * SIGN_WIDTH),
                           schar_from_ascii(' '), win_hl_attr(wp, HLF_SC));
      }

      // draw the number column
      if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) == NULL) {
        int width = number_width(wp) + 1;
        n = grid_line_fill(n, MIN(view_width, n + width),
                           schar_from_ascii(' '), win_hl_attr(wp, HLF_N));
      }