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

Code before:
        }
      }
    }
    // Check if there are more filler lines than allowed.
    if (!check_topline && wp->w_topfill > win_get_fill(wp, wp->w_topline)) {
      check_topline = true;
    }

    if (check_topline) {
      int halfheight = wp->w_view_height / 2 - 1;
      if (halfheight < 2) {
        halfheight = 2;
      }
      int64_t n;
      if (win_lines_concealed(wp)) {
        // Count the number of logical lines between the cursor and
        // topline + p_so (approximation of how much will be
        // scrolled).
        n = 0;
        for (linenr_T lnum = wp->w_cursor.lnum; lnum < wp->w_topline + *so_ptr; lnum++) {
          // stop at end of file or when we know we are far off
          assert(wp->w_buffer != 0);
          if (lnum >= wp->w_buffer->b_ml.ml_line_count || n >= halfheight) {
            break;
          }
          n += !decor_conceal_line(wp, lnum, false);
          hasFolding(wp, lnum, NULL, &lnum);
        }
      } else {
        n = wp->w_topline + *so_ptr - wp->w_cursor.lnum;
      }

      // If we weren't very close to begin with, we scroll to put the
      // cursor in the middle of the window.  Otherwise put the cursor
      // near the top of the window.
      if (n >= halfheight) {
        scroll_cursor_halfway(wp, false, false);
      } else {
        scroll_cursor_top(wp, scrolljump_value(wp), false);
        check_botline = true;
      }
    } else {
      // Make sure topline is the first line of a fold.
      hasFolding(wp, wp->w_topline, &wp->w_topline, NULL);
      check_botline = true;
    }
  }

  // If the cursor is below the bottom of the window, scroll the window
  // to put the cursor on the window.
  // When w_botline is invalid, recompute it first, to avoid a redraw later.

Review comment (suggestion):
```suggestion
          if (lnum >= wp->w_buffer->b_ml.ml_line_count
              || (n += !decor_conceal_line(wp, lnum, false)) >= halfheight) {
            break;
          }
```

Code after:
        }
      }
    }
    // Check if there are more filler lines than allowed.
    if (!check_topline && wp->w_topfill > win_get_fill(wp, wp->w_topline)) {
      check_topline = true;
    }

    if (check_topline) {
      int halfheight = wp->w_view_height / 2 - 1;
      if (halfheight < 2) {
        halfheight = 2;
      }
      int64_t n;
      if (win_lines_concealed(wp)) {
        // Count the number of logical lines between the cursor and
        // topline + p_so (approximation of how much will be
        // scrolled).
        n = 0;
        for (linenr_T lnum = wp->w_cursor.lnum; lnum < wp->w_topline + *so_ptr; lnum++) {
          // stop at end of file or when we know we are far off
          assert(wp->w_buffer != 0);
          if (lnum >= wp->w_buffer->b_ml.ml_line_count
              || (n += !decor_conceal_line(wp, lnum, false)) >= halfheight) {
            break;
          }
          hasFolding(wp, lnum, NULL, &lnum);
        }
      } else {
        n = wp->w_topline + *so_ptr - wp->w_cursor.lnum;
      }

      // If we weren't very close to begin with, we scroll to put the
      // cursor in the middle of the window.  Otherwise put the cursor
      // near the top of the window.
      if (n >= halfheight) {
        scroll_cursor_halfway(wp, false, false);
      } else {
        scroll_cursor_top(wp, scrolljump_value(wp), false);
        check_botline = true;
      }
    } else {
      // Make sure topline is the first line of a fold.
      hasFolding(wp, wp->w_topline, &wp->w_topline, NULL);
      check_botline = true;
    }
  }

  // If the cursor is below the bottom of the window, scroll the window
  // to put the cursor on the window.
  // When w_botline is invalid, recompute it first, to avoid a redraw later.