From dac0aa1d894219676363cd1c42c52ec1fd21688d Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Sat, 16 Apr 2016 21:17:55 +0200
Subject: [PATCH] inserting: prune some superfluous settings, and do one
 differently

When we don't set edittop in read_line(), we don't need to readjust it in
read_file(), because in that particular case it will still be pointing at
current.  And since fileptr is a new, freshly created line, it can never
be equal to filebot, so there is no point in comparing them.

If more than one line was inserted at the beginning of the file, leave it
up to the screen handling to set edittop to what it should be.

Move the setting of fileage a bit down, to its sister setting: the line
at current gets "connected" either to the top-of-file pointer or to the
last line of the inserted file.
---
 src/files.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/files.c b/src/files.c
index a9b59772..f4949ab3 100644
--- a/src/files.c
+++ b/src/files.c
@@ -708,8 +708,6 @@ filestruct *read_line(char *buf, size_t buf_len, filestruct *prevnode)
 	freshline->next = openfile->fileage;
 	openfile->fileage = freshline;
 	freshline->lineno = 1;
-	/* Make sure that our edit window stays on the first line. */
-	openfile->edittop = freshline;
     } else {
 	prevnode->next = freshline;
 	freshline->next = NULL;
@@ -897,22 +895,18 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
 			current_len + 1);
 	    strncpy(openfile->current->data, fileptr->data, len);
 
-	    /* Don't destroy fileage, edittop, or filebot! */
-	    if (fileptr == openfile->fileage)
-		openfile->fileage = openfile->current;
-	    if (fileptr == openfile->edittop)
-		openfile->edittop = openfile->current;
-	    if (fileptr == openfile->filebot)
-		openfile->filebot = openfile->current;
-
 	    /* Step back one line, and blow away the unterminated line,
 	     * since its text has been copied into current. */
 	    fileptr = fileptr->prev;
 	    delete_node(dropline);
 	}
 
-	/* Attach the line at current after the line at fileptr. */
-	if (fileptr != NULL) {
+	if (fileptr == NULL)
+	    /* After inserting a single unterminated line at the top,
+	     * readjust the top-of-file pointer. */
+	    openfile->fileage = openfile->current;
+	else {
+	    /* Attach the line at current after the line at fileptr. */
 	    fileptr->next = openfile->current;
 	    openfile->current->prev = fileptr;
 	}
-- 
GitLab