From b97c36c2184d0c6a7123d81ec6a8fabda253b7ba Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Mon, 25 Apr 2016 20:05:21 +0200
Subject: [PATCH] screen: don't always set 'edit_refresh_needed' when adjusting
 edittop

The function edit_update() is called by edit_refresh() itself, so it is
silly that the first sets 'edit_refresh_needed' to TRUE.  This setting
is needed only in a few cases -- in the others it's not needed because
the screen does not need to be refreshed (it was just about positioning
the cursor), or 'edit_refresh_needed' has already been set by a call to
goto_line_posx().  So, just set the flag in the five places that need it
and spare the other four calls.
---
 src/files.c  | 5 ++---
 src/move.c   | 2 ++
 src/nano.c   | 4 +++-
 src/search.c | 1 +
 src/winio.c  | 5 +++--
 5 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/files.c b/src/files.c
index 06497d1d..d08f54de 100644
--- a/src/files.c
+++ b/src/files.c
@@ -1262,9 +1262,6 @@ void do_insertfile(
 
 #ifndef DISABLE_MULTIBUFFER
 	    if (ISSET(MULTIBUFFER)) {
-		/* Update the screen to account for the current buffer. */
-		display_buffer();
-
 #ifndef DISABLE_HISTORIES
 		if (ISSET(POS_HISTORY)) {
 		    ssize_t priorline, priorcol;
@@ -1275,6 +1272,8 @@ void do_insertfile(
 			do_gotolinecolumn(priorline, priorcol, FALSE, FALSE);
 		}
 #endif /* !DISABLE_HISTORIES */
+		/* Update the screen to account for the current buffer. */
+		display_buffer();
 	    } else
 #endif /* !DISABLE_MULTIBUFFER */
 	    {
diff --git a/src/move.c b/src/move.c
index 77ed490d..dbb61b04 100644
--- a/src/move.c
+++ b/src/move.c
@@ -97,6 +97,7 @@ void do_page_up(void)
 
     /* Scroll the edit window up a page. */
     edit_update(STATIONARY);
+    edit_refresh_needed = TRUE;
 }
 
 /* Move down one page. */
@@ -137,6 +138,7 @@ void do_page_down(void)
 
     /* Scroll the edit window down a page. */
     edit_update(STATIONARY);
+    edit_refresh_needed = TRUE;
 }
 
 #ifndef DISABLE_JUSTIFY
diff --git a/src/nano.c b/src/nano.c
index 5d4a40f3..ea61284e 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -403,8 +403,10 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
 
     /* If the top of the edit window was inside the old partition, put
      * it in range of current. */
-    if (edittop_inside)
+    if (edittop_inside) {
 	edit_update(STATIONARY);
+	edit_refresh_needed = TRUE;
+    }
 
     /* Renumber starting with the beginning line of the old
      * partition. */
diff --git a/src/search.c b/src/search.c
index 5de296ad..6aa8fe0f 100644
--- a/src/search.c
+++ b/src/search.c
@@ -242,6 +242,7 @@ int search_init(bool replacing, bool use_answer)
     } else if (func == do_gotolinecolumn_void) {
 	do_gotolinecolumn(openfile->current->lineno,
 			openfile->placewewant + 1, TRUE, TRUE);
+	edit_refresh_needed = TRUE;
 	return 3;
     }
 
diff --git a/src/winio.c b/src/winio.c
index 0bdd60fc..b1355db7 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2954,8 +2954,10 @@ void edit_redraw(filestruct *old_current)
 
     /* If the current line is offscreen, scroll until it's onscreen. */
     if (openfile->current->lineno >= openfile->edittop->lineno + maxrows ||
-		openfile->current->lineno < openfile->edittop->lineno)
+		openfile->current->lineno < openfile->edittop->lineno) {
 	edit_update((focusing || !ISSET(SMOOTH_SCROLL)) ? CENTERING : FLOWING);
+	edit_refresh_needed = TRUE;
+    }
 
 #ifndef NANO_TINY
     /* If the mark is on, update all lines between old_current and current. */
@@ -3070,7 +3072,6 @@ void edit_update(update_type manner)
     fprintf(stderr, "edit_update(): setting edittop to lineno %ld\n", (long)openfile->edittop->lineno);
 #endif
     compute_maxrows();
-    edit_refresh_needed = TRUE;
 }
 
 /* Unconditionally redraw the entire screen. */
-- 
GitLab