/* Move to the first line of the file. */
void do_first_line(void)
{
- openfile->current = openfile->fileage;
+ openfile->current = openfile->edittop = openfile->fileage;
openfile->current_x = 0;
openfile->placewewant = 0;
/* If there's less than a page of text left on the screen, put the
* cursor at the beginning of the last line of the file, and then
* update the edit window. */
- if (openfile->current->lineno + editwinrows - 2 >=
+ if (openfile->current->lineno + maxrows - 2 >=
openfile->filebot->lineno) {
do_last_line();
return;
}
#endif
- for (i = editwinrows - 2; i > 0 && openfile->current !=
- openfile->filebot; i--)
+#ifdef DEBUG
+ fprintf(stderr, "do_page_down: maxrows = %d\n", maxrows);
+#endif
+
+ for (i = maxrows - 2; i > 0 && openfile->current !=
+ openfile->filebot; i--) {
openfile->current = openfile->current->next;
+#ifdef DEBUG
+ fprintf(stderr, "do_page_down: moving to line %d\n", openfile->current->lineno);
+#endif
+
+ }
openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
/* Scroll the edit window down a page. */
- edit_scroll(DOWN_DIR, editwinrows - 2);
+ edit_scroll(DOWN_DIR, maxrows - 2);
}
#ifndef DISABLE_JUSTIFY
/* Should we temporarily disable constant cursor position
* display? */
-static int maxrows = 0;
- /* With soft wrapping, how many lines really fit on the curent page */
-
/* Control character compatibility:
*
* - NANO_BACKSPACE_KEY is Ctrl-H, which is Backspace under ASCII, ANSI,
int n;
filestruct *foo = openfile->edittop;
+ if (!ISSET(SOFTWRAP)) {
+ maxrows = editwinrows;
+ return;
+ }
+
maxrows = 0;
for (n = 0; n < editwinrows && foo; n++) {
maxrows += 1 - strlenpt(foo->data) / COLS;
foo = foo->next;
}
+ if (n < editwinrows)
+ maxrows += editwinrows - n;
+
#ifdef DEBUG
fprintf(stderr, "compute_maxrows(): maxrows = %ld\n", maxrows);
#endif
-
}
/* Scroll the edit window in the given direction and the given number
}
}
+ compute_maxrows();
/* Limit nlines to the number of lines we could scroll. */
nlines -= i;
else
edit_scroll(DOWN_DIR, nlines);
- compute_maxrows();
-
#ifndef NANO_TINY
/* If the mark is on, update all the lines between the old first
* line or old last line of the edit window (depending on
int nlines;
/* Figure out what maxrows should really be */
- if (openfile->current->lineno > openfile->edittop->lineno)
- compute_maxrows();
+ compute_maxrows();
if (openfile->current->lineno < openfile->edittop->lineno ||
openfile->current->lineno >= openfile->edittop->lineno +
- maxrows)
+ maxrows) {
+
+#ifdef DEBUG
+ fprintf(stderr, "edit_refresh(): line = %d, edittop %d + maxrows %d\n", openfile->current->lineno, openfile->edittop->lineno, maxrows);
+#endif
+
/* Put the top line of the edit window in range of the current
* line. */
edit_update(
ISSET(SMOOTH_SCROLL) ? NONE :
#endif
CENTER);
+ }
foo = openfile->edittop;
* screen as before, or at the top or bottom of the screen if
* edittop is beyond either. */
if (location == CENTER)
- goal = editwinrows / 2;
+ goal = maxrows / 2;
else {
goal = openfile->current_y;
/* Limit goal to (editwinrows - 1) lines maximum. */
- if (goal > editwinrows - 1)
- goal = editwinrows - 1;
+ if (goal > maxrows - 1)
+ goal = maxrows - 1;
}
for (; goal > 0 && foo->prev != NULL; goal--) {
if (ISSET(SOFTWRAP))
- goal -= strlenpt(foo->data) / COLS;
+ goal -= 1 + strlenpt(foo->data) / COLS;
foo = foo->prev;
}
openfile->edittop = foo;
+ compute_maxrows();
}
/* Unconditionally redraw the entire screen. */