nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] cutting: when ^K does not actually cut anything, do


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] cutting: when ^K does not actually cut anything, do not add an undo item
Date: Sun, 30 Dec 2018 12:32:36 +0100

This addresses https://savannah.gnu.org/bugs/?55330.
---
 src/cut.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/cut.c b/src/cut.c
index 0f33e1d4..76a8201d 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -118,7 +118,6 @@ void do_cut_text(bool copy_text, bool marked, bool 
cut_till_eof, bool append)
        bool right_side_up = TRUE;
                /* There *is* no region, *or* it is marked forward. */
 #endif
-       size_t was_totsize = openfile->totsize;
 
        /* If cuts were not continuous, or when cutting a region, clear the 
slate. */
        if (!append && (!keep_cutbuffer || marked || cut_till_eof)) {
@@ -177,16 +176,26 @@ void do_cut_text(bool copy_text, bool marked, bool 
cut_till_eof, bool append)
                        UNSET(NO_NEWLINES);
        } else
 #endif /* !NANO_TINY */
-       /* Only set the modification flag if actually something was cut. */
-       if (openfile->totsize != was_totsize)
-               set_modified();
-
        refresh_needed = TRUE;
 }
 
 /* Move text from the current buffer into the cutbuffer. */
 void do_cut_text_void(void)
 {
+       /* When on an empty line at EOF, there is nothing to cut. */
+       if (openfile->current->next == NULL && openfile->current->data[0] == 
'\0') {
+#ifndef NANO_TINY
+               openfile->mark = NULL;
+               return;
+       }
+       /* When the mark covers zero characters, there is nothing to cut. */
+       if (openfile->mark == openfile->current &&
+                       openfile->mark_x == openfile->current_x) {
+               openfile->mark = NULL;
+#endif
+               return;
+       }
+
 #ifndef NANO_TINY
        /* Only add a new undo item when the current item is not a CUT or when
         * the current cut is not contiguous with the previous cutting. */
-- 
2.19.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]