From 17fb6dfdc0f12e20b6fbe99199e2ed8319a8b011 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Thu, 16 Jun 2016 11:54:11 +0200
Subject: [PATCH] tweaks: reshuffle two lines and improve two comments

---
 src/nano.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/nano.c b/src/nano.c
index 2014d537..b53e1f04 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -437,14 +437,14 @@ void copy_from_filestruct(filestruct *somebuffer)
 #endif
 
     /* Partition the filestruct so that it contains no text, and remember
-     * whether the top of the edit window is at the start of the buffer. */
+     * whether the current line is at the top of the edit window. */
     filepart = partition_filestruct(openfile->current, openfile->current_x,
 				openfile->current, openfile->current_x);
     edittop_inside = (openfile->edittop == openfile->fileage);
+    free_filestruct(openfile->fileage);
 
     /* Put the top and bottom of the current filestruct at the top and
      * bottom of a copy of the passed buffer. */
-    free_filestruct(openfile->fileage);
     openfile->fileage = copy_filestruct(somebuffer);
     openfile->filebot = openfile->fileage;
     while (openfile->filebot->next != NULL)
@@ -487,13 +487,13 @@ void copy_from_filestruct(filestruct *somebuffer)
      * tacked onto the current line. */
     openfile->current_y += openfile->filebot->lineno - 1;
 
-    top_save = openfile->fileage;
-
-    /* If the top of the edit window is inside the partition, set it to
-     * where the copied text now starts. */
+    /* If we pasted onto the first line of the edit window, the corresponding
+     * struct has been freed, so... point at the start of the copied text. */
     if (edittop_inside)
 	openfile->edittop = openfile->fileage;
 
+    top_save = openfile->fileage;
+
     /* Unpartition the filestruct so that it contains all the text
      * again, plus the copied text. */
     unpartition_filestruct(&filepart);
-- 
GitLab