From 76e150b47f1ef74ec8b1023597e51636de9a5913 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Sat, 21 Jun 2014 19:32:17 +0000
Subject: [PATCH] When undoing a cut-till-end-of-file, put the cursor back
 where the cut started, and not at the bottom of the file. Patch by Mark
 Majeres.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5005 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog  | 4 ++++
 src/text.c | 6 ++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 564a0e2f..b7e0b346 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2014-06-21  Mark Majeres  <mark@engine12.com>
+	* src/text.c (undo_cut, add_undo): When undoing a cut-till-eof,
+	put the cursor back where the cut started, and not at the end.
+
 2014-06-21  David Lawrence Ramsey  <pooka109@gmail.com>
 	* src/move.c, src/nano.c: Miscellaneous whitespace fixes, one
 	type fix, and one more #ifdef NANO_TINY.
diff --git a/src/text.c b/src/text.c
index 791dab9b..8138d20a 100644
--- a/src/text.c
+++ b/src/text.c
@@ -396,7 +396,7 @@ void undo_cut(undo *u)
     free_filestruct(cutbuffer);
     cutbuffer = NULL;
 
-    if (u->xflags == UNcut_cutline || u->xflags == UNcut_marked_backwards)
+    if (u->xflags == UNcut_cutline || u->xflags == UNcut_marked_backwards || u->type == CUT_EOF)
 	goto_line_posx(u->mark_begin_lineno, u->mark_begin_x);
 }
 
@@ -937,6 +937,8 @@ void add_undo(undo_type current_action)
 	u->strdata = data;
 	break;
     case CUT_EOF:
+	cutbuffer_reset();
+	break;
     case CUT:
 	cutbuffer_reset();
 	u->mark_set = openfile->mark_set;
@@ -944,7 +946,7 @@ void add_undo(undo_type current_action)
 	    u->mark_begin_lineno = openfile->mark_begin->lineno;
 	    u->mark_begin_x = openfile->mark_begin_x;
 	}
-	else if (!ISSET(CUT_TO_END) && u->type != CUT_EOF) {
+	else if (!ISSET(CUT_TO_END)) {
 	    /* The entire line is being cut regardless of the cursor position. */
 	    u->begin = 0;
 	    u->xflags = UNcut_cutline;
-- 
GitLab