From acb394aec0c165f827381165f9e541bf77501a54 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Thu, 5 Jan 2017 21:38:00 -0600
Subject: [PATCH] screen: properly place the cursor after inserting a file

Instead of setting openfile->current_y (and wrongly so), just call
reset_cursor() to recompute current_y and place the cursor on that
line (if it is not offscreen).
---
 src/files.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/files.c b/src/files.c
index b1c5f5ad..e30c47fb 100644
--- a/src/files.c
+++ b/src/files.c
@@ -1111,7 +1111,6 @@ void do_insertfile(void)
 	    filestruct *edittop_save = openfile->edittop;
 	    ssize_t was_current_lineno = openfile->current->lineno;
 	    size_t was_current_x = openfile->current_x;
-	    ssize_t was_current_y = openfile->current_y;
 	    bool current_was_at_top = FALSE;
 #if !defined(NANO_TINY) || !defined(DISABLE_BROWSER)
 	    functionptrtype func = func_from_key(&i);
@@ -1257,9 +1256,6 @@ void do_insertfile(void)
 		    }
 		}
 #endif
-		/* Update the current y-coordinate to account for the
-		 * number of lines inserted. */
-		openfile->current_y += was_current_y;
 
 		/* Unpartition the filestruct so that it contains all
 		 * the text again.  Note that we've replaced the
@@ -1282,6 +1278,10 @@ void do_insertfile(void)
 			openfile->current_x != was_current_x)
 		    set_modified();
 
+		/* Update the cursor position to account for the number
+		 * of lines inserted. */
+		reset_cursor();
+
 		refresh_needed = TRUE;
 	    }
 
-- 
GitLab