commit edf6995be43a396a8a111c1f8f9076be5c213db5
parent b50d5758efd5b528b59e6458f41fc676b50c3660
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Fri, 3 May 2019 17:36:09 +0200
zapping: use the 'keep_cutbuffer' logic to keep undo items apart
The 'keep_cutbuffer' variable becomes FALSE whenever there is cursor
movement or there was a marked region. Use this variable to simplify
the condition for creating a new ZAP undo item. But then typing the
'zap' shortcut should not cause the variable to be set to FALSE.
This fixes the first part of https://savannah.gnu.org/bugs/?56261.
Bug existed since zapping was introduced, in version 3.2.
Diffstat:
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/cut.c b/src/cut.c
@@ -380,8 +380,10 @@ void do_cut_text_void(void)
/* 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. */
- if (openfile->last_action != CUT || !keep_cutbuffer)
+ if (openfile->last_action != CUT || !keep_cutbuffer) {
+ keep_cutbuffer = FALSE;
add_undo(CUT);
+ }
do_cut_text(FALSE, openfile->mark != NULL, FALSE, FALSE);
@@ -450,9 +452,7 @@ void zap_text(void)
/* 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->mark != NULL ||
- openfile->current_undo->mark_begin_lineno != openfile->current->lineno ||
- openfile->current_undo->xflags & (MARK_WAS_SET|WAS_MARKED_FORWARD))
+ if (openfile->last_action != ZAP || !keep_cutbuffer)
add_undo(ZAP);
/* Use the cutbuffer from the ZAP undo item, so the cut can be undone. */
diff --git a/src/nano.c b/src/nano.c
@@ -1723,7 +1723,7 @@ void do_input(void)
/* When not cutting or copying text, drop the cutbuffer the next time. */
if (shortcut->func != do_cut_text_void) {
#ifndef NANO_TINY
- if (shortcut->func != do_copy_text)
+ if (shortcut->func != do_copy_text && shortcut->func != zap_text)
#endif
keep_cutbuffer = FALSE;
}