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

Code before:

  // Let the syntax stuff know we stop parsing here.
  if (syntax_last_parsed != 0 && syntax_present(wp)) {
    syntax_end_parsing(wp, syntax_last_parsed + 1);
  }

  const linenr_T old_botline = wp->w_botline;

  // If we didn't hit the end of the file, and we didn't finish the last
  // line we were working on, then the line didn't fit.
  wp->w_empty_rows = 0;
  wp->w_filler_rows = 0;
  if (!eof && !didline) {
    int at_attr = hl_combine_attr(win_bg_attr(wp), win_hl_attr(wp, HLF_AT));
    if (lnum == wp->w_topline) {
      // Single line that does not fit!
      // Don't overwrite it, it can be edited.
      wp->w_botline = lnum + 1;
    } else if (win_get_fill(wp, lnum) >= wp->w_view_height - srow) {
      // Window ends in filler lines.
      wp->w_botline = lnum;
      wp->w_filler_rows = wp->w_view_height - srow;
    } else if (dy_flags & kOptDyFlagTruncate) {      // 'display' has "truncate"
      // Last line isn't finished: Display "@@@" in the last screen line.
      grid_line_start(&wp->w_grid, wp->w_view_height - 1, wp->w_view_width);
      grid_line_fill(0, MIN(wp->w_view_width, 3), wp->w_p_fcs_chars.lastline, at_attr);
      grid_line_fill(3, wp->w_view_width, schar_from_ascii(' '), at_attr);
      grid_line_flush();
      set_empty_rows(wp, srow);
      wp->w_botline = lnum;
    } else if (dy_flags & kOptDyFlagLastline) {      // 'display' has "lastline"
      // Last line isn't finished: Display "@@@" at the end.
      // If this would split a doublewidth char in two, we need to display "@@@@" instead
      grid_line_start(&wp->w_grid, wp->w_view_height - 1, wp->w_view_width);
      int width = grid_line_getchar(MAX(wp->w_view_width - 3, 0), NULL) == NUL ? 4 : 3;
      grid_line_fill(MAX(wp->w_view_width - width, 0), wp->w_view_width,
                     wp->w_p_fcs_chars.lastline, at_attr);
      grid_line_flush();
      set_empty_rows(wp, srow);
      wp->w_botline = lnum;
    } else {
      win_draw_end(wp, wp->w_p_fcs_chars.lastline, true, srow,
                   wp->w_view_height, HLF_AT);
      set_empty_rows(wp, srow);
      wp->w_botline = lnum;
    }
  } else {
    if (eof) {  // we hit the end of the file
      wp->w_botline = buf->b_ml.ml_line_count + 1;
      int j = win_get_fill(wp, wp->w_botline);
      if (j > 0 && !wp->w_botfill && row < wp->w_view_height) {

Review comment (suggestion):
Hmm its a bit weird that just specifying `MIN(wp->w_view_width, 3)`  isn't enough. `grid_line_flush()` is not supposed to touch cells outside the total [min, max) range of all interleaving calls...

Code after:

  // Let the syntax stuff know we stop parsing here.
  if (syntax_last_parsed != 0 && syntax_present(wp)) {
    syntax_end_parsing(wp, syntax_last_parsed + 1);
  }

  const linenr_T old_botline = wp->w_botline;

  // If we didn't hit the end of the file, and we didn't finish the last
  // line we were working on, then the line didn't fit.
  wp->w_empty_rows = 0;
  wp->w_filler_rows = 0;
  if (!eof && !didline) {
    int at_attr = hl_combine_attr(win_bg_attr(wp), win_hl_attr(wp, HLF_AT));
    if (lnum == wp->w_topline) {
      // Single line that does not fit!
      // Don't overwrite it, it can be edited.
      wp->w_botline = lnum + 1;
    } else if (win_get_fill(wp, lnum) >= wp->w_view_height - srow) {
      // Window ends in filler lines.
      wp->w_botline = lnum;
      wp->w_filler_rows = wp->w_view_height - srow;
    } else if (dy_flags & kOptDyFlagTruncate) {      // 'display' has "truncate"
      // Last line isn't finished: Display "@@@" in the last screen line.
      grid_line_start(&wp->w_grid, wp->w_view_height - 1);
      grid_line_fill(0, MIN(wp->w_view_width, 3), wp->w_p_fcs_chars.lastline, at_attr);
      grid_line_fill(3, wp->w_view_width, schar_from_ascii(' '), at_attr);
      grid_line_flush();
      set_empty_rows(wp, srow);
      wp->w_botline = lnum;
    } else if (dy_flags & kOptDyFlagLastline) {      // 'display' has "lastline"
      // Last line isn't finished: Display "@@@" at the end.
      // If this would split a doublewidth char in two, we need to display "@@@@" instead
      grid_line_start(&wp->w_grid, wp->w_view_height - 1);
      int width = grid_line_getchar(MAX(wp->w_view_width - 3, 0), NULL) == NUL ? 4 : 3;
      grid_line_fill(MAX(wp->w_view_width - width, 0), wp->w_view_width,
                     wp->w_p_fcs_chars.lastline, at_attr);
      grid_line_flush();
      set_empty_rows(wp, srow);
      wp->w_botline = lnum;
    } else {
      win_draw_end(wp, wp->w_p_fcs_chars.lastline, true, srow,
                   wp->w_view_height, HLF_AT);
      set_empty_rows(wp, srow);
      wp->w_botline = lnum;
    }
  } else {
    if (eof) {  // we hit the end of the file
      wp->w_botline = buf->b_ml.ml_line_count + 1;
      int j = win_get_fill(wp, wp->w_botline);
      if (j > 0 && !wp->w_botfill && row < wp->w_view_height) {