From 1458891b9fbeab09356b870f21bf9f61dcddef2f Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Thu, 14 Jul 2005 20:37:01 +0000 Subject: [PATCH] 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 --- src/move.c | 27 +++++++++++++++++---------- src/winio.c | 34 +++++++++++++--------------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/move.c b/src/move.c index 3ea27e70..02202cdd 100644 --- a/src/move.c +++ b/src/move.c @@ -114,14 +114,14 @@ void do_page_up(void) #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); } @@ -137,6 +137,7 @@ void do_page_up(void) } #endif + /* Scroll the edit window down a page. */ edit_scroll(UP, editwinrows - 2); } @@ -160,14 +161,15 @@ void do_page_down(void) #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); } @@ -183,6 +185,7 @@ void do_page_down(void) } #endif + /* Scroll the edit window down a page. */ edit_scroll(DOWN, editwinrows - 2); } @@ -202,13 +205,15 @@ void do_up(void) 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 @@ -238,13 +243,15 @@ void do_down(void) 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 diff --git a/src/winio.c b/src/winio.c index 6dcb743d..e6c494cf 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3503,11 +3503,8 @@ int need_vertical_update(size_t old_pww) /* 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; @@ -3528,43 +3525,38 @@ void edit_scroll(updown direction, int nlines) 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 -- 2.39.5