]> git.wh0rd.org Git - nano.git/commitdiff
- When undoing a cut, set cutbuffer to NULL after freeing the current one
authorChris Allegretta <chrisa@asty.org>
Fri, 1 Aug 2008 06:52:15 +0000 (06:52 +0000)
committerChris Allegretta <chrisa@asty.org>
Fri, 1 Aug 2008 06:52:15 +0000 (06:52 +0000)
- 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

src/text.c

index c0629a8f488af89fe64653ed62d68b54870f9320..d70060b94e5ff7a9e5097c07938f980f4aa4a38b 100644 (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;