2009-11-24 Chris Allegretta <chrisa@asty.org>
        * 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
diff --git a/src/move.c b/src/move.c
index f22e6fe..4c87747 100644
--- a/src/move.c
+++ b/src/move.c
@@ -50,18 +50,19 @@
 /* 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 @@
     }
 #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 @@
     }
 #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 0e21d2d..c617fc8 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2949,7 +2949,8 @@
 
     maxrows = 0;
     for (n = 0; n < editwinrows && foo; n++) {
-	maxrows += 1 - strlenpt(foo->data) / COLS;
+	maxrows ++;
+	n += strlenpt(foo->data) / COLS;
 	foo = foo->next;
     }