From e2df2c899dde28b29229e77f3f7529c6eb452181 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Tue, 24 Nov 2009 17:15:53 +0000 Subject: [PATCH] 2009-11-24 Chris Allegretta * move.c (do_page_up, do_page_down): Make these functions work better with soft line wrapping. * winio.c (compute_maxrows): Make maxrows calculation more accurate when all lines are > COLS. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4441 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++++ src/move.c | 25 +++++++++++++++---------- src/winio.c | 3 ++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0bc76d7c..3c0197d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-11-24 Chris Allegretta + * move.c (do_page_up, do_page_down): Make these functions work better with soft + line wrapping. + * winio.c (compute_maxrows): Make maxrows calculation more accurate when all lines are > COLS. + 2009-11-22 Chris Allegretta * nano.c (main): Allow edit_refresh_needed to take effect when using --enable-tiny (fixes Savannah bug 28076 reported by David Lawrence Ramsey). diff --git a/src/move.c b/src/move.c index f22e6fea..4c877472 100644 --- a/src/move.c +++ b/src/move.c @@ -50,18 +50,19 @@ void do_last_line(void) /* Move up one page. */ void do_page_up(void) { - int i; + int i, skipped = 0; /* If there's less than a page of text left on the screen, put the * cursor at the beginning of the first line of the file, and then * update the edit window. */ - if (openfile->current->lineno <= editwinrows - 2) { + if (!ISSET(SOFTWRAP) && openfile->current->lineno <= editwinrows - 2) { do_first_line(); return; } /* If we're not in smooth scrolling mode, put the cursor at the * beginning of the top line of the edit window, as Pico does. */ + #ifndef NANO_TINY if (!ISSET(SMOOTH_SCROLL)) { #endif @@ -71,15 +72,23 @@ void do_page_up(void) } #endif - for (i = editwinrows - 2; i > 0 && openfile->current != - openfile->fileage; i--) + for (i = editwinrows - 2; i - skipped > 0 && openfile->current != + openfile->fileage; i--) { openfile->current = openfile->current->prev; + if (ISSET(SOFTWRAP) && openfile->current) + skipped += strlenpt(openfile->current->data) / COLS; + + } openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); +#ifdef DEBUG + fprintf(stderr, "do_page_up: openfile->current->lineno = %lu, skipped = %d\n", (unsigned long) openfile->current->lineno, skipped); +#endif + /* Scroll the edit window up a page. */ - edit_scroll(UP_DIR, editwinrows - 2); + edit_scroll(UP_DIR, editwinrows - skipped - 2); } /* Move down one page. */ @@ -107,15 +116,11 @@ void do_page_down(void) } #endif -#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); + fprintf(stderr, "do_page_down: moving to line %lu\n", (unsigned long) openfile->current->lineno); #endif } diff --git a/src/winio.c b/src/winio.c index 0e21d2d6..c617fc8b 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2949,7 +2949,8 @@ void compute_maxrows(void) maxrows = 0; for (n = 0; n < editwinrows && foo; n++) { - maxrows += 1 - strlenpt(foo->data) / COLS; + maxrows ++; + n += strlenpt(foo->data) / COLS; foo = foo->next; }