Index: src/cut.c =================================================================== --- src/cut.c (revision 4966) +++ src/cut.c (working copy) @@ -26,16 +26,20 @@ #include #include -static bool keep_cutbuffer = FALSE; - /* Should we keep the contents of the cutbuffer? */ - /* Pointer to the end of the cutbuffer. */ - /* Indicate that we should no longer keep the contents of the * cutbuffer. */ void cutbuffer_reset(void) { - keep_cutbuffer = FALSE; + /* If keep_cutbuffer is FALSE and the cutbuffer isn't empty, blow + * away the text in the cutbuffer. */ + if (cutbuffer != NULL) { + free_filestruct(cutbuffer); + cutbuffer = NULL; +#ifdef DEBUG + fprintf(stderr, "Blew away cutbuffer =)\n"); +#endif } +} /* 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 @@ -136,16 +140,6 @@ assert(openfile->current != NULL && openfile->current->data != NULL); - /* If keep_cutbuffer is FALSE and the cutbuffer isn't empty, blow - * away the text in the cutbuffer. */ - if (!keep_cutbuffer && cutbuffer != NULL) { - free_filestruct(cutbuffer); - cutbuffer = NULL; -#ifdef DEBUG - fprintf(stderr, "Blew away cutbuffer =)\n"); -#endif - } - #ifndef NANO_TINY if (copy_text) { if (cutbuffer != NULL) { @@ -161,11 +155,6 @@ } #endif - /* Set keep_cutbuffer to TRUE, so that the text we're going to move - * into the cutbuffer will be added to the text already in the - * cutbuffer instead of replacing it. */ - keep_cutbuffer = TRUE; - #ifndef NANO_TINY if (cut_till_end) { /* If cut_till_end is TRUE, move all text up to the end of the @@ -248,7 +237,17 @@ * back into the filestruct afterward. */ void do_copy_text(void) { + static struct filestruct * next_contiguous_line = 0; + bool mark_set = openfile->mark_set; + if(mark_set || openfile->current != next_contiguous_line) + cutbuffer_reset(); + do_cut_text(TRUE, FALSE, FALSE); + + if(!mark_set) + next_contiguous_line = openfile->current; + else + next_contiguous_line = 0; } /* Cut from the current cursor position to the end of the file. */ Index: src/move.c =================================================================== --- src/move.c (revision 4966) +++ src/move.c (working copy) @@ -495,6 +495,7 @@ #endif ) { + cutbuffer_reset(); /* If we're at the top of the file, or if scroll_only is TRUE and * the top of the file is onscreen, get out. */ if (openfile->current == openfile->fileage @@ -571,6 +572,8 @@ filestruct *topline; #endif + cutbuffer_reset(); + /* If we're at the bottom of the file, get out. */ if (openfile->current == openfile->filebot || !openfile->current->next) return; @@ -671,6 +674,7 @@ if (need_horizontal_update(pww_save)) update_line(openfile->current, openfile->current_x); + cutbuffer_reset(); } /* Move right one character. */ @@ -692,4 +696,5 @@ if (need_horizontal_update(pww_save)) update_line(openfile->current, openfile->current_x); + cutbuffer_reset(); } Index: src/nano.c =================================================================== --- src/nano.c (revision 4966) +++ src/nano.c (working copy) @@ -1573,8 +1573,6 @@ /* The input buffer. */ static size_t kbinput_len = 0; /* The length of the input buffer. */ - bool preserve = FALSE; - /* Preserve the contents of the cutbuffer? */ const sc *s; bool have_shortcut; @@ -1667,15 +1665,6 @@ } if (have_shortcut) { - /* If the function associated with this shortcut is - * cutting or copying text, remember this. */ - if (s->scfunc == do_cut_text_void -#ifndef NANO_TINY - || s->scfunc == do_copy_text || s->scfunc == do_cut_till_end -#endif - ) - preserve = TRUE; - if (s->scfunc != 0) { const subnfunc *f = sctofunc((sc *) s); if (ISSET(VIEW_MODE) && f && !f->viewok) @@ -1684,7 +1673,6 @@ #ifndef NANO_TINY if (s->scfunc == do_toggle_void) { do_toggle(s->toggle); - preserve = TRUE; } else #endif { @@ -1708,11 +1696,6 @@ } } - /* If we aren't cutting or copying text, and the key wasn't a toggle, - * blow away the text in the cutbuffer upon the next cutting action. */ - if (!preserve) - cutbuffer_reset(); - return input; } Index: src/text.c =================================================================== --- src/text.c (revision 4966) +++ src/text.c (working copy) @@ -858,7 +858,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) || + ((cutbuffer && current_action == CUT && u->type == CUT && !u->mark_set) || (current_action == ADD && u->type == ADD && u->mark_begin_x == fs->current_x))) return; @@ -945,6 +945,7 @@ 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;