#ifndef NANO_SMALL
/* If we're in smooth scrolling mode and there's at least one
* page of text left, move the current line of the edit window
- * up a page. */
+ * up a page, and then get the equivalent x-coordinate of the
+ * current line. */
if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno >
editwinrows - 2) {
int i = 0;
for (; i < editwinrows - 2; i++)
openfile->current = openfile->current->prev;
- /* Get the equivalent x-coordinate of the new line. */
openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
}
}
#endif
+ /* Scroll the edit window down a page. */
edit_scroll(UP, editwinrows - 2);
}
#ifndef NANO_SMALL
/* If we're in smooth scrolling mode and there's at least one
* page of text left, move the current line of the edit window
- * down a page. */
+ * down a page, and then get the equivalent x-coordinate of the
+ * current line. */
if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno +
editwinrows - 2 <= openfile->filebot->lineno) {
int i = 0;
+
for (; i < editwinrows - 2; i++)
openfile->current = openfile->current->next;
- /* Get the equivalent x-coordinate of the new line. */
openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
}
}
#endif
+ /* Scroll the edit window down a page. */
edit_scroll(DOWN, editwinrows - 2);
}
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
+ /* Move the current line of the edit window up, and then get the
+ * equivalent x-coordinate of the current line. */
openfile->current = openfile->current->prev;
openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
- /* If we're on the first row of the edit window, scroll up one line
- * if we're in smooth scrolling mode, or up half a page if we're
- * not. */
+ /* If we're on the first row of the edit window, scroll the edit
+ * window up one line if we're in smooth scrolling mode, or up half
+ * a page if we're not. */
if (openfile->current_y == 0)
edit_scroll(UP,
#ifndef NANO_SMALL
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
+ /* Move the current line of the edit window down, and then get the
+ * equivalent x-coordinate of the current line. */
openfile->current = openfile->current->next;
openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
- /* If we're on the last row of the edit window, scroll down one line
- * if we're in smooth scrolling mode, or down half a page if we're
- * not. */
+ /* If we're on the last row of the edit window, scroll the edit
+ * window down one line if we're in smooth scrolling mode, or down
+ * half a page if we're not. */
if (openfile->current_y == editwinrows - 1)
edit_scroll(DOWN,
#ifndef NANO_SMALL
/* Scroll the edit window in the given direction and the given number
* of lines, and draw new lines on the blank lines left after the
* scrolling. direction is the direction to scroll, either UP or DOWN,
- * and nlines is the number of lines to scroll. Don't redraw the old
- * topmost or bottommost line (where we assume current is) before
- * scrolling or draw the new topmost or bottommost line after scrolling
- * (where we assume current will be), since we don't know where we are
- * on the page or whether we'll stay there. */
+ * and nlines is the number of lines to scroll. We assume that current
+ * and current_x are up to date, and only change edittop. */
void edit_scroll(updown direction, int nlines)
{
filestruct *foo;
if (openfile->edittop->prev == NULL)
break;
openfile->edittop = openfile->edittop->prev;
- scroll_rows--;
} else {
if (openfile->edittop->next == NULL)
break;
openfile->edittop = openfile->edittop->next;
- scroll_rows++;
}
+
+ scroll_rows++;
}
/* Scroll the text on the screen up or down scroll_rows lines,
* depending on the value of direction. */
scrollok(edit, TRUE);
- wscrl(edit, scroll_rows);
+ wscrl(edit, (direction == UP) ? -scroll_rows : scroll_rows);
scrollok(edit, FALSE);
foo = openfile->edittop;
- if (direction != UP) {
- int slines = editwinrows - nlines - 1;
- for (; slines > 0 && foo != NULL; slines--)
+
+ if (direction == DOWN) {
+ for (i = editwinrows - nlines - 1; i > 0 && foo != NULL; i--)
foo = foo->next;
}
- /* And draw new lines on the blank top or bottom lines of the edit
+ /* Draw new lines on the blank top or bottom lines of the edit
* window, depending on the value of direction. */
- while (foo != NULL && scroll_rows != 0) {
+ scroll_rows++;
+
+ while (scroll_rows > 0 && foo != NULL) {
update_line(foo, (foo == openfile->current) ?
openfile->current_x : 0);
foo = foo->next;
-
- if (direction == UP)
- scroll_rows++;
- else
- scroll_rows--;
+ scroll_rows--;
}
-
- update_line(foo, (foo == openfile->current) ?
- openfile->current_x : 0);
}
/* Update any lines between old_current and current that need to be