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.
master
Benno Schulenberg 2018-06-02 17:57:19 +02:00
parent 33d81fa1e6
commit 71f859377d
3 changed files with 4 additions and 7 deletions

View File

@ -125,12 +125,12 @@ void do_cut_text(bool copy_text, bool cut_till_eof)
#endif #endif
size_t was_totsize = openfile->totsize; size_t was_totsize = openfile->totsize;
/* If a chain of cuts was broken, empty the cutbuffer. */ /* If cuts were not continuous, or when cutting a region, clear the slate. */
if (!keep_cutbuffer) { if (!keep_cutbuffer || openfile->mark || cut_till_eof) {
free_filestruct(cutbuffer); free_filestruct(cutbuffer);
cutbuffer = NULL; cutbuffer = NULL;
/* Indicate that future cuts should add to the cutbuffer. */ /* After a line cut, future line cuts should add to the cutbuffer. */
keep_cutbuffer = TRUE; keep_cutbuffer = !openfile->mark && !cut_till_eof;
} }
#ifndef NANO_TINY #ifndef NANO_TINY

View File

@ -1759,7 +1759,6 @@ int do_input(bool allow_funcs)
if (shortcut->func == do_cut_text_void if (shortcut->func == do_cut_text_void
#ifndef NANO_TINY #ifndef NANO_TINY
|| shortcut->func == do_copy_text || shortcut->func == do_copy_text
|| shortcut->func == do_cut_till_eof
#endif #endif
) )
retain_cuts = TRUE; retain_cuts = TRUE;

View File

@ -1395,10 +1395,8 @@ void add_undo(undo_type action)
break; break;
#endif #endif
case CUT_TO_EOF: case CUT_TO_EOF:
cutbuffer_reset();
break; break;
case CUT: case CUT:
cutbuffer_reset();
if (openfile->mark) { if (openfile->mark) {
u->mark_begin_lineno = openfile->mark->lineno; u->mark_begin_lineno = openfile->mark->lineno;
u->mark_begin_x = openfile->mark_x; u->mark_begin_x = openfile->mark_x;