* position to the end of the file into the cutbuffer. */
void do_cut_text(
#ifndef NANO_TINY
- bool copy_text, bool cut_till_end
+ bool copy_text, bool cut_till_end, bool undoing
#else
void
#endif
* disturbing the text. */
if (!old_no_newlines)
UNSET(NO_NEWLINES);
- } else
+ } else if (!undoing)
update_undo(CUT, openfile);
#endif
/* Leave the text in the cutbuffer, and mark the file as
add_undo(CUT, openfile);
do_cut_text(
#ifndef NANO_TINY
- FALSE, FALSE
+ FALSE, FALSE, FALSE
#endif
);
}
* back into the filestruct afterward. */
void do_copy_text(void)
{
- do_cut_text(TRUE, FALSE);
+ do_cut_text(TRUE, FALSE, FALSE);
}
/* Cut from the current cursor position to the end of the file. */
void do_cut_till_end(void)
{
add_undo(CUTTOEND, openfile);
- do_cut_text(FALSE, TRUE);
+ do_cut_text(FALSE, TRUE, FALSE);
}
#endif /* !NANO_TINY */
openfile->mark_begin = t;
}
openfile->mark_begin_x = u->mark_begin_x;
- do_cut_text(FALSE, u->to_end);
+ do_cut_text(FALSE, u->to_end, TRUE);
openfile->mark_set = FALSE;
openfile->mark_begin = NULL;
openfile->mark_begin_x = 0;
char *data;
/* Blow away the old undo stack if we are starting from the middle */
- while (fs->undotop != fs->current_undo) {
- undo *tmp = fs->undotop;
+ while (fs->undotop != NULL && fs->undotop != fs->current_undo) {
+ undo *u2 = fs->undotop;
fs->undotop = fs->undotop->next;
- free(tmp->strdata);
- free(tmp);
+ if (u2->strdata != NULL)
+ free(u2->strdata);
+ while (u2->cutbuffer != NULL) {
+ filestruct *f2 = u2->cutbuffer->next;
+ u2->cutbuffer = u2->cutbuffer->next;
+ free(f2);
+ }
+ free(u2);
}
u->type = current_action;
u->next = fs->undotop;
fs->undotop = u;
fs->current_undo = u;
+ u->strdata = NULL;
+ u->cutbuffer = NULL;
+ u->cutbottom = NULL;
+ u->xflags = 0;
switch (u->type) {
/* We need to start copying data into the undo buffer or we wont be able
char *data;
int len = 0;
+
+#ifdef DEBUG
+ fprintf(stderr, "action = %d, fs->last_action = %d, openfile->current->lineno = %d, fs->current_undo->lineno = %d\n",
+ action, fs->last_action, openfile->current->lineno, fs->current_undo->lineno);
+#endif
+
/* Change to an add if we're not using the same undo struct
that we should be using */
if (action != fs->last_action
|| (action != CUT && action != CUTTOEND
- && openfile->current->lineno != fs->undotop->lineno)) {
+ && openfile->current->lineno != fs->current_undo->lineno)) {
add_undo(action, fs);
return;
}