[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH V2] cutting: when ^K does not actually cut anything,
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH V2] cutting: when ^K does not actually cut anything, do not add an undo item |
Date: |
Sun, 30 Dec 2018 14:38:48 +0100 |
V2:
* DO set modified state when something was actually cut.
* Only when the mark is off should a final empty line not be cut.
* Cover also the zap function.
This addresses https://savannah.gnu.org/bugs/?55330.
---
src/cut.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/src/cut.c b/src/cut.c
index 0341c598..4124f7fd 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. */
@@ -239,6 +258,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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Nano-devel] [PATCH V2] cutting: when ^K does not actually cut anything, do not add an undo item,
Benno Schulenberg <=