commit 71f859377d4716a6663813c42be8723f4d86f768
parent 33d81fa1e62ddc1a45e13f53f5ed7e84f42e7d44
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sat, 2 Jun 2018 17:57:19 +0200
cut: concentrate the logic for clearing the cutbuffer mostly in one place
It should not be the task of the undo code to take care that the
cutbuffer will be cleared at the right moments.
Diffstat:
3 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/cut.c b/src/cut.c
@@ -125,12 +125,12 @@ void do_cut_text(bool copy_text, bool cut_till_eof)
#endif
size_t was_totsize = openfile->totsize;
- /* If a chain of cuts was broken, empty the cutbuffer. */
- if (!keep_cutbuffer) {
+ /* If cuts were not continuous, or when cutting a region, clear the slate. */
+ if (!keep_cutbuffer || openfile->mark || cut_till_eof) {
free_filestruct(cutbuffer);
cutbuffer = NULL;
- /* Indicate that future cuts should add to the cutbuffer. */
- keep_cutbuffer = TRUE;
+ /* After a line cut, future line cuts should add to the cutbuffer. */
+ keep_cutbuffer = !openfile->mark && !cut_till_eof;
}
#ifndef NANO_TINY
diff --git a/src/nano.c b/src/nano.c
@@ -1759,7 +1759,6 @@ int do_input(bool allow_funcs)
if (shortcut->func == do_cut_text_void
#ifndef NANO_TINY
|| shortcut->func == do_copy_text
- || shortcut->func == do_cut_till_eof
#endif
)
retain_cuts = TRUE;
diff --git a/src/text.c b/src/text.c
@@ -1395,10 +1395,8 @@ void add_undo(undo_type action)
break;
#endif
case CUT_TO_EOF:
- cutbuffer_reset();
break;
case CUT:
- cutbuffer_reset();
if (openfile->mark) {
u->mark_begin_lineno = openfile->mark->lineno;
u->mark_begin_x = openfile->mark_x;