From d35ecd02b8da9cf62ac79a5528a0946450a1aa00 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Sat, 7 Jan 2017 14:51:49 -0600
Subject: [PATCH] weeding: remove another unnecessary setting of
 openfile->current_y

The setting of current_y in copy_from_filestruct() also appears to be
a holdover from the days of a more-common STATIONARY scrolling mode.

do_cut_text() uses the above function when copying text (uncutting
text again right after cutting it).  Since the text is effectively
the same afterward, current_y doesn't need to change.

do_uncut_text(), however, does need current_y up to date in one case:
when uncutting a full screen or less' worth of lines, focusing will be
FALSE, and it uses edit_refresh(), so it will use STATIONARY scrolling
mode then.  Take a cue from do_insertfile() and call reset_cursor() to
get an updated current_y.

(Note that the check for a full screen or less' worth of lines uses
incorrect values when in softwrap mode, but that's a separate problem.)

undo_cut(), do_redo(), and backup_lines() do not need set current_y
because they all result in edit_refresh() with focusing = TRUE, so
they do a CENTERING scroll which does not need current_y.
---
 src/cut.c  | 3 +++
 src/nano.c | 5 -----
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/cut.c b/src/cut.c
index a00d705d..aa42d943 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -284,6 +284,9 @@ void do_uncut_text(void)
     /* Mark the file as modified. */
     set_modified();
 
+    /* Update the cursor position to account for the inserted lines. */
+    reset_cursor();
+
     refresh_needed = TRUE;
 
 #ifndef DISABLE_COLOR
diff --git a/src/nano.c b/src/nano.c
index 0e371d50..d1dba354 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -469,11 +469,6 @@ void copy_from_filestruct(filestruct *somebuffer)
     /* Add the number of characters in the copied text to the file size. */
     openfile->totsize += get_totsize(openfile->fileage, openfile->filebot);
 
-    /* Update the current y-coordinate to account for the number of
-     * lines the copied text has, less one since the first line will be
-     * tacked onto the current line. */
-    openfile->current_y += openfile->filebot->lineno - 1;
-
     /* 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)
-- 
GitLab