From b802a13c5ae73fdfa4fa251d86cfa4bf1cebb0e4 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Thu, 14 Jul 2005 22:15:09 +0000 Subject: [PATCH] it turns out edit_redraw() is needed after all when doing PageUp/PageDown; revert all the movement code and edit_scroll() changes except for added comments and edit_scroll() simplifications git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2860 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 6 ++-- src/move.c | 79 +++++++++++++++++++++++++++++------------------------ src/winio.c | 17 ++++++------ 3 files changed, 53 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index 24138c2b..f1ee5a93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -34,10 +34,6 @@ CVS code - (DLR) - Consistently make the flags global and any variables used to hold it longs. (DLR) - - Tweak the movement routines to redraw all necessary lines - instead of relying on edit_redraw(). Changes to - do_page_up(), do_page_down(), do_up(), do_down(), and - edit_scroll(). (DLR) - Consistently make the fg and bg colortype struct entries and any variables used to hold them shorts. Changes to do_colorinit() (renamed color_init()), color_to_int() (renamed @@ -101,6 +97,8 @@ CVS code - - Blank out last_replace properly again just before displaying the "Replace" prompt. (DLR, found by Mike Frysinger) - winio.c: + edit_scroll() + - Clean up and simplify. (DLR) do_statusbar_next_word() - Rework to be more like do_statusbar_prev_word(), to avoid a potential problem if we start at the end of a line. (DLR) diff --git a/src/move.c b/src/move.c index 02202cdd..928fbdf1 100644 --- a/src/move.c +++ b/src/move.c @@ -100,6 +100,9 @@ void do_end(void) void do_page_up(void) { + const filestruct *current_save = openfile->current; + size_t pww_save = openfile->placewewant; + #ifndef DISABLE_WRAPPING wrap_reset(); #endif @@ -108,22 +111,21 @@ void do_page_up(void) * and put the cursor at the beginning of the line. */ if (openfile->edittop == openfile->fileage) { openfile->current = openfile->fileage; - openfile->current_x = 0; openfile->placewewant = 0; } else { + /* Scroll the edit window up 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 - * up a page, and then get the equivalent x-coordinate of the - * current line. */ + * up a page. */ if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno > editwinrows - 2) { int i = 0; + for (; i < editwinrows - 2; i++) openfile->current = openfile->current->prev; - - openfile->current_x = actual_x(openfile->current->data, - openfile->placewewant); } /* If we're not in smooth scrolling mode or there isn't at least * one page of text left, put the cursor at the beginning of the @@ -131,21 +133,27 @@ void do_page_up(void) else { #endif openfile->current = openfile->edittop; - openfile->current_x = 0; openfile->placewewant = 0; #ifndef NANO_SMALL } #endif - - /* Scroll the edit window down a page. */ - edit_scroll(UP, editwinrows - 2); } + /* Get the equivalent x-coordinate of the current line. */ + openfile->current_x = actual_x(openfile->current->data, + openfile->placewewant); + + /* Update the screen. */ + edit_redraw(current_save, pww_save); + check_statusblank(); } void do_page_down(void) { + const filestruct *current_save = openfile->current; + size_t pww_save = openfile->placewewant; + #ifndef DISABLE_WRAPPING wrap_reset(); #endif @@ -155,23 +163,21 @@ void do_page_down(void) if (openfile->edittop->lineno + editwinrows > openfile->filebot->lineno) { openfile->current = openfile->filebot; - openfile->current_x = 0; openfile->placewewant = 0; } else { + /* Scroll the edit window down a page. */ + edit_scroll(DOWN, 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, and then get the equivalent x-coordinate of the - * current line. */ + * down a page. */ 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; - - openfile->current_x = actual_x(openfile->current->data, - openfile->placewewant); } /* If we're not in smooth scrolling mode or there isn't at least * one page of text left, put the cursor at the beginning of the @@ -179,16 +185,19 @@ void do_page_down(void) else { #endif openfile->current = openfile->edittop; - openfile->current_x = 0; openfile->placewewant = 0; #ifndef NANO_SMALL } #endif - - /* Scroll the edit window down a page. */ - edit_scroll(DOWN, editwinrows - 2); } + /* Get the equivalent x-coordinate of the current line. */ + openfile->current_x = actual_x(openfile->current->data, + openfile->placewewant); + + /* Update the screen. */ + edit_redraw(current_save, pww_save); + check_statusblank(); } @@ -220,14 +229,13 @@ void do_up(void) ISSET(SMOOTH_SCROLL) ? 1 : #endif editwinrows / 2); - /* Otherwise, update the line we were on before and the line we're - * on now. The former needs to be redrawn if we're not on the first - * page, and the latter needs to be redrawn unconditionally. */ - else { - if (need_vertical_update(0)) - update_line(openfile->current->next, 0); - update_line(openfile->current, openfile->current_x); - } + + /* Update the line we were on before and the line we're on now. The + * former needs to be redrawn if we're not on the first page, and + * the latter needs to be drawn unconditionally. */ + if (need_vertical_update(0)) + update_line(openfile->current->next, 0); + update_line(openfile->current, openfile->current_x); } void do_down(void) @@ -258,14 +266,13 @@ void do_down(void) ISSET(SMOOTH_SCROLL) ? 1 : #endif editwinrows / 2); - /* Otherwise, update the line we were on before and the line we're - * on now. The former needs to be redrawn if we're not on the first - * page, and the latter needs to be redrawn unconditionally. */ - else { - if (need_vertical_update(0)) - update_line(openfile->current->prev, 0); - update_line(openfile->current, openfile->current_x); - } + + /* Update the line we were on before and the line we're on now. The + * former needs to be redrawn if we're not on the first page, and + * the latter needs to be drawn unconditionally. */ + if (need_vertical_update(0)) + update_line(openfile->current->prev, 0); + update_line(openfile->current, openfile->current_x); } void do_left(bool allow_update) diff --git a/src/winio.c b/src/winio.c index e6c494cf..2c6c70a4 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3503,8 +3503,11 @@ 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. We assume that current - * and current_x are up to date, and only change edittop. */ + * and nlines is the number of lines to scroll. + * + * Note that we don't draw the topmost or bottommost lines before or + * after scrolling, since we can make no assumptions about which of the + * two is the current line. */ void edit_scroll(updown direction, int nlines) { filestruct *foo; @@ -3543,19 +3546,15 @@ void edit_scroll(updown direction, int nlines) foo = openfile->edittop; if (direction == DOWN) { - for (i = editwinrows - nlines - 1; i > 0 && foo != NULL; i--) + for (i = editwinrows - scroll_rows; i > 0 && foo != NULL; i--) foo = foo->next; } /* Draw new lines on the blank top or bottom lines of the edit * window, depending on the value of direction. */ - scroll_rows++; - - while (scroll_rows > 0 && foo != NULL) { - update_line(foo, (foo == openfile->current) ? - openfile->current_x : 0); + for (; scroll_rows > 0 && foo != NULL; scroll_rows--) { + update_line(foo, 0); foo = foo->next; - scroll_rows--; } }