From bd1c5d7c63e961061575af04757a8c4aa09c01cf Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Sun, 21 Aug 2016 15:49:39 +0200
Subject: [PATCH] moving: make PgUp and PgDown functional also in very flat
 terminals

Even when the edit window consists of just one or two lines, the PageUp
and PageDown functions (^Y and ^V) should continue to move the window.

This fixes https://savannah.gnu.org/bugs/?48805.
---
 src/move.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/move.c b/src/move.c
index 3523ec64..3b2ec29d 100644
--- a/src/move.c
+++ b/src/move.c
@@ -50,7 +50,7 @@ void do_last_line(void)
 /* Move up one page. */
 void do_page_up(void)
 {
-    int i, skipped = 0;
+    int i, mustmove, skipped = 0;
 
     /* If the cursor is less than a page away from the top of the file,
      * put it at the beginning of the first line. */
@@ -73,8 +73,9 @@ void do_page_up(void)
 	openfile->placewewant = openfile->current_y = 0;
     }
 
-    for (i = editwinrows - 2; i - skipped > 0 && openfile->current !=
-	openfile->fileage; i--) {
+    mustmove = (editwinrows < 3) ? 1 : editwinrows - 2;
+
+    for (i = mustmove; i - skipped > 0 && openfile->current != openfile->fileage; i--) {
 	openfile->current = openfile->current->prev;
 #ifndef NANO_TINY
 	if (ISSET(SOFTWRAP) && openfile->current) {
@@ -103,7 +104,7 @@ void do_page_up(void)
 /* Move down one page. */
 void do_page_down(void)
 {
-    int i;
+    int i, mustmove;
 
     /* If the cursor is less than a page away from the bottom of the file,
      * put it at the end of the last line. */
@@ -122,8 +123,9 @@ void do_page_down(void)
 	openfile->placewewant = openfile->current_y = 0;
     }
 
-    for (i = maxrows - 2; i > 0 && openfile->current !=
-	openfile->filebot; i--) {
+    mustmove = (maxrows < 3) ? 1 : maxrows - 2;
+
+    for (i = mustmove; i > 0 && openfile->current != openfile->filebot; i--) {
 	openfile->current = openfile->current->next;
 #ifdef DEBUG
 	fprintf(stderr, "do_page_down: moving to line %lu\n", (unsigned long)openfile->current->lineno);
-- 
GitLab