From a872709ab426e51e6f4caf7c3d232bbe66011943 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 18 Jun 2014 19:04:35 +0000 Subject: [PATCH] Making sure the cutbuffer is cleared at the appropriate moments. Patch by Mark Majeres. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4978 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 10 ++++++++++ src/cut.c | 18 +++++++++++++++++- src/proto.h | 1 + src/text.c | 3 ++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 197b5dc7..ef20ef2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2014-06-18 Mark Majeres + * src/text.c (add_undo): Don't start a new undo for CUT when the + cutbuffer is being preserved, because then the cuts are contiguous + and will form a single undo item. And make sure the cutbuffer will + be cleared when a new undo item for CUT is created. + * src/cut.c (keeping_cutbuffer): New function, to access the status + of 'keep_cutbuffer' from the undo/redo code in src/text.c. + * src/cut.c (do_copy_text): Blow away the contents of the cutbuffer + if the mark is set or the cursor has moved between two copy commands. + 2014-06-17 Mark Majeres * src/text.c (do_undo, do_redo): After an undo or redo, update the 'placewewant' (the desired horizontal position of the cursor). diff --git a/src/cut.c b/src/cut.c index 70dbde93..56ece31c 100644 --- a/src/cut.c +++ b/src/cut.c @@ -37,6 +37,12 @@ void cutbuffer_reset(void) keep_cutbuffer = FALSE; } +/* Return the status of cutbuffer preservation. */ +inline bool keeping_cutbuffer(void) +{ + return keep_cutbuffer; +} + /* If we aren't on the last line of the file, move all the text of the * current line, plus the newline at the end, into the cutbuffer. If we * are, move all of the text of the current line into the cutbuffer. In @@ -245,10 +251,20 @@ void do_cut_text_void(void) #ifndef NANO_TINY /* Move text from the current filestruct into the cutbuffer, and copy it - * back into the filestruct afterward. */ + * back into the filestruct afterward. If the mark is set or the cursor + * was moved, blow away previous contents of the cutbuffer. */ void do_copy_text(void) { + static struct filestruct *next_contiguous_line = NULL; + bool mark_set = openfile->mark_set; + + if (mark_set || openfile->current != next_contiguous_line) + cutbuffer_reset(); + do_cut_text(TRUE, FALSE, FALSE); + + /* If the mark was set, blow away the cutbuffer on the next copy. */ + next_contiguous_line = (mark_set ? NULL : openfile->current); } /* Cut from the current cursor position to the end of the file. */ diff --git a/src/proto.h b/src/proto.h index 18ce2345..97b62b29 100644 --- a/src/proto.h +++ b/src/proto.h @@ -249,6 +249,7 @@ void color_update(void); /* All functions in cut.c. */ void cutbuffer_reset(void); +bool keeping_cutbuffer(void); void cut_line(void); #ifndef NANO_TINY void cut_marked(void); diff --git a/src/text.c b/src/text.c index e8a97d29..4eb49cd2 100644 --- a/src/text.c +++ b/src/text.c @@ -854,7 +854,7 @@ void add_undo(undo_type current_action) * on the same lineno, we need to abort here. */ u = fs->current_undo; if (u && u->mark_begin_lineno == fs->current->lineno && - ((current_action == CUT && u->type == CUT && !u->mark_set) || + ((current_action == CUT && u->type == CUT && !u->mark_set && keeping_cutbuffer()) || (current_action == ADD && u->type == ADD && u->mark_begin_x == fs->current_x))) return; @@ -941,6 +941,7 @@ void add_undo(undo_type current_action) case CUT_EOF: u->to_end = TRUE; case CUT: + cutbuffer_reset(); u->mark_set = openfile->mark_set; if (u->mark_set) { u->mark_begin_lineno = openfile->mark_begin->lineno;