[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH 1/2 V3] cutting: when ^K does not actually cut anyth
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH 1/2 V3] cutting: when ^K does not actually cut anything, do not add an undo item |
Date: |
Mon, 31 Dec 2018 13:24:05 +0100 |
V3:
Do the check for M-T too (cut-to-end-of-buffer).
This addresses https://savannah.gnu.org/bugs/?55330.
---
src/cut.c | 33 +++++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/src/cut.c b/src/cut.c
index 0341c598..7cb6a862 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -109,7 +109,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)) {
@@ -168,16 +167,36 @@ 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();
+ set_modified();
refresh_needed = TRUE;
}
+/* Return TRUE when a cut command would not actually cut anything: when
+ * on an empty line at EOF, or when the mark covers zero characters. */
+bool nothing_needs_cutting(void)
+{
+ if ((openfile->current->next == NULL && openfile->current->data[0] ==
'\0'
+#ifndef NANO_TINY
+ && openfile->mark == NULL) ||
+ (openfile->mark == openfile->current &&
+ openfile->mark_x == openfile->current_x
+#endif
+ )) {
+#ifndef NANO_TINY
+ openfile->mark = NULL;
+#endif
+ return TRUE;
+ } else
+ return FALSE;
+}
+
/* Move text from the current buffer into the cutbuffer. */
void do_cut_text_void(void)
{
+ if (nothing_needs_cutting())
+ 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. */
@@ -227,6 +246,9 @@ void do_copy_text(void)
/* Cut from the current cursor position to the end of the file. */
void do_cut_till_eof(void)
{
+ if (openfile->current->next == NULL && openfile->current->data[0] ==
'\0')
+ return;
+
add_undo(CUT_TO_EOF);
do_cut_text(FALSE, FALSE, TRUE, FALSE);
update_undo(CUT_TO_EOF);
@@ -239,6 +261,9 @@ void zap_text(void)
filestruct *was_cutbuffer = cutbuffer;
filestruct *was_cutbottom = cutbottom;
+ if (nothing_needs_cutting())
+ return;
+
/* Add a new undo item only when the current item is not a ZAP or when
* the current zap is not contiguous with the previous zapping. */
if (openfile->last_action != ZAP || openfile->current_undo == NULL ||
--
2.19.2
- [Nano-devel] [PATCH 1/2 V3] cutting: when ^K does not actually cut anything, do not add an undo item,
Benno Schulenberg <=