Commit 1458891b authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

add comments, and fix some edit_scroll() breakage

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2859 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent d2361f07
Showing with 30 additions and 31 deletions
+30 -31
...@@ -114,14 +114,14 @@ void do_page_up(void) ...@@ -114,14 +114,14 @@ void do_page_up(void)
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* If we're in smooth scrolling mode and there's at least one /* 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 * 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 > if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno >
editwinrows - 2) { editwinrows - 2) {
int i = 0; int i = 0;
for (; i < editwinrows - 2; i++) for (; i < editwinrows - 2; i++)
openfile->current = openfile->current->prev; openfile->current = openfile->current->prev;
/* Get the equivalent x-coordinate of the new line. */
openfile->current_x = actual_x(openfile->current->data, openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant); openfile->placewewant);
} }
...@@ -137,6 +137,7 @@ void do_page_up(void) ...@@ -137,6 +137,7 @@ void do_page_up(void)
} }
#endif #endif
/* Scroll the edit window down a page. */
edit_scroll(UP, editwinrows - 2); edit_scroll(UP, editwinrows - 2);
} }
...@@ -160,14 +161,15 @@ void do_page_down(void) ...@@ -160,14 +161,15 @@ void do_page_down(void)
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* If we're in smooth scrolling mode and there's at least one /* 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 * 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 + if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno +
editwinrows - 2 <= openfile->filebot->lineno) { editwinrows - 2 <= openfile->filebot->lineno) {
int i = 0; int i = 0;
for (; i < editwinrows - 2; i++) for (; i < editwinrows - 2; i++)
openfile->current = openfile->current->next; openfile->current = openfile->current->next;
/* Get the equivalent x-coordinate of the new line. */
openfile->current_x = actual_x(openfile->current->data, openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant); openfile->placewewant);
} }
...@@ -183,6 +185,7 @@ void do_page_down(void) ...@@ -183,6 +185,7 @@ void do_page_down(void)
} }
#endif #endif
/* Scroll the edit window down a page. */
edit_scroll(DOWN, editwinrows - 2); edit_scroll(DOWN, editwinrows - 2);
} }
...@@ -202,13 +205,15 @@ void do_up(void) ...@@ -202,13 +205,15 @@ void do_up(void)
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno); 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 = openfile->current->prev;
openfile->current_x = actual_x(openfile->current->data, openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant); openfile->placewewant);
/* If we're on the first row of the edit window, scroll up one line /* If we're on the first row of the edit window, scroll the edit
* if we're in smooth scrolling mode, or up half a page if we're * window up one line if we're in smooth scrolling mode, or up half
* not. */ * a page if we're not. */
if (openfile->current_y == 0) if (openfile->current_y == 0)
edit_scroll(UP, edit_scroll(UP,
#ifndef NANO_SMALL #ifndef NANO_SMALL
...@@ -238,13 +243,15 @@ void do_down(void) ...@@ -238,13 +243,15 @@ void do_down(void)
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno); 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 = openfile->current->next;
openfile->current_x = actual_x(openfile->current->data, openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant); openfile->placewewant);
/* If we're on the last row of the edit window, scroll down one line /* If we're on the last row of the edit window, scroll the edit
* if we're in smooth scrolling mode, or down half a page if we're * window down one line if we're in smooth scrolling mode, or down
* not. */ * half a page if we're not. */
if (openfile->current_y == editwinrows - 1) if (openfile->current_y == editwinrows - 1)
edit_scroll(DOWN, edit_scroll(DOWN,
#ifndef NANO_SMALL #ifndef NANO_SMALL
......
...@@ -3503,11 +3503,8 @@ int need_vertical_update(size_t old_pww) ...@@ -3503,11 +3503,8 @@ int need_vertical_update(size_t old_pww)
/* Scroll the edit window in the given direction and the given number /* 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 * of lines, and draw new lines on the blank lines left after the
* scrolling. direction is the direction to scroll, either UP or DOWN, * 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 * and nlines is the number of lines to scroll. We assume that current
* topmost or bottommost line (where we assume current is) before * and current_x are up to date, and only change edittop. */
* 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. */
void edit_scroll(updown direction, int nlines) void edit_scroll(updown direction, int nlines)
{ {
filestruct *foo; filestruct *foo;
...@@ -3528,43 +3525,38 @@ void edit_scroll(updown direction, int nlines) ...@@ -3528,43 +3525,38 @@ void edit_scroll(updown direction, int nlines)
if (openfile->edittop->prev == NULL) if (openfile->edittop->prev == NULL)
break; break;
openfile->edittop = openfile->edittop->prev; openfile->edittop = openfile->edittop->prev;
scroll_rows--;
} else { } else {
if (openfile->edittop->next == NULL) if (openfile->edittop->next == NULL)
break; break;
openfile->edittop = openfile->edittop->next; openfile->edittop = openfile->edittop->next;
scroll_rows++;
} }
scroll_rows++;
} }
/* Scroll the text on the screen up or down scroll_rows lines, /* Scroll the text on the screen up or down scroll_rows lines,
* depending on the value of direction. */ * depending on the value of direction. */
scrollok(edit, TRUE); scrollok(edit, TRUE);
wscrl(edit, scroll_rows); wscrl(edit, (direction == UP) ? -scroll_rows : scroll_rows);
scrollok(edit, FALSE); scrollok(edit, FALSE);
foo = openfile->edittop; foo = openfile->edittop;
if (direction != UP) {
int slines = editwinrows - nlines - 1; if (direction == DOWN) {
for (; slines > 0 && foo != NULL; slines--) for (i = editwinrows - nlines - 1; i > 0 && foo != NULL; i--)
foo = foo->next; 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. */ * 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) ? update_line(foo, (foo == openfile->current) ?
openfile->current_x : 0); openfile->current_x : 0);
foo = foo->next; 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 /* Update any lines between old_current and current that need to be
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment