- When undoing a cut, set cutbuffer to NULL after freeing the current one

- When updating a normal consecutive ^K cut, bail from add_undo since it's not an add, and in update_undo free the old cutbuffer before copying it again.



git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4287 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2008-08-01 06:52:15 +00:00
parent 1f37c4514d
commit 8f76112084
1 changed files with 12 additions and 1 deletions

View File

@ -451,6 +451,7 @@ void do_undo(void)
do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE);
do_uncut_text();
free_filestruct(cutbuffer);
cutbuffer = NULL;
break;
default:
undidmsg = _("wtf?");
@ -731,9 +732,15 @@ bool execute_command(const char *command)
/* Add a new undo struct to the top of the current pile */
void add_undo(undo_type current_action, openfilestruct *fs)
{
undo *u = nmalloc(sizeof(undo));
undo *u;
char *data;
/* Ugh, if we were called while cutting not-to-end, non-marked and on the same lineno,
we need to abort here */
u = fs->current_undo;
if (u && u->type == CUT && !u->mark_set && u->lineno == fs->current->lineno)
return;
/* Blow away the old undo stack if we are starting from the middle */
while (fs->undotop != NULL && fs->undotop != fs->current_undo) {
undo *u2 = fs->undotop;
@ -748,6 +755,8 @@ void add_undo(undo_type current_action, openfilestruct *fs)
free(u2);
}
/* Allocate and initialize a new undo type */
u = nmalloc(sizeof(undo));
u->type = current_action;
u->lineno = fs->current->lineno;
u->begin = fs->current_x;
@ -895,6 +904,8 @@ void update_undo(undo_type action, openfilestruct *fs)
case CUT:
case CUTTOEND:
case UNCUT:
if (u->cutbuffer)
free(u->cutbuffer);
u->cutbuffer = copy_filestruct(cutbuffer);
u->cutbottom = cutbottom;
break;