+2014-06-18 Mark Majeres <mark@engine12.com>
+ * 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 <mark@engine12.com>
* src/text.c (do_undo, do_redo): After an undo or redo, update the
'placewewant' (the desired horizontal position of the cursor).
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
#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. */
/* All functions in cut.c. */
void cutbuffer_reset(void);
+bool keeping_cutbuffer(void);
void cut_line(void);
#ifndef NANO_TINY
void cut_marked(void);
* 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;
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;