Index: src/proto.h =================================================================== --- src/proto.h (revision 4977) +++ src/proto.h (working copy) @@ -249,6 +249,7 @@ /* All functions in cut.c. */ void cutbuffer_reset(void); +bool keeping_cutbuffer(void); void cut_line(void); #ifndef NANO_TINY void cut_marked(void); Index: src/text.c =================================================================== --- src/text.c (revision 4977) +++ src/text.c (working copy) @@ -854,7 +854,7 @@ * 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; Index: src/cut.c =================================================================== --- src/cut.c (revision 4977) +++ src/cut.c (working copy) @@ -37,6 +37,12 @@ keep_cutbuffer = FALSE; } +/* Returns 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 @@ -172,10 +178,11 @@ * file into the cutbuffer. */ cut_to_eof(); } else if (openfile->mark_set) { - /* If the mark is on, move the marked text to the cutbuffer, and - * turn the mark off. */ + /* If the mark is on, move the marked text to the cutbuffer, turn + * the mark off, and blow away the cutbuffer on the next cut. */ cut_marked(); openfile->mark_set = FALSE; + cutbuffer_reset(); } else if (ISSET(CUT_TO_END)) /* If the CUT_TO_END flag is set, move all text up to the end of * the line into the cutbuffer. */ @@ -245,10 +252,20 @@ #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. */