From 598e0af7aff754fc21d318dc7ea7cf276c20681a Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Thu, 15 Sep 2016 10:43:49 +0200
Subject: [PATCH] softwrap: scroll the current line fully into view when
 jumping words

This fixes https://savannah.gnu.org/bugs/?47710
and fixes https://savannah.gnu.org/bugs/?49088.
---
 src/winio.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/winio.c b/src/winio.c
index b2abd456..eccf41c1 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2970,8 +2970,13 @@ void edit_update(update_type manner)
     if (manner == CENTERING)
 	goal = editwinrows / 2;
     else if (manner == FLOWING) {
-	if (openfile->current->lineno >= openfile->edittop->lineno)
+	if (openfile->current->lineno >= openfile->edittop->lineno) {
 	    goal = editwinrows - 1;
+#ifndef NANO_TINY
+	    if (ISSET(SOFTWRAP))
+		goal -= strlenpt(openfile->current->data) / COLS ;
+#endif
+	}
     } else {
 	goal = openfile->current_y;
 
@@ -2986,8 +2991,11 @@ void edit_update(update_type manner)
 	openfile->edittop = openfile->edittop->prev;
 	goal --;
 #ifndef NANO_TINY
-	if (ISSET(SOFTWRAP))
+	if (ISSET(SOFTWRAP)) {
 	    goal -= strlenpt(openfile->edittop->data) / COLS;
+	    if (goal < 0)
+		openfile->edittop = openfile->edittop->next;
+	}
 #endif
     }
 #ifdef DEBUG
-- 
GitLab