]> git.deb.at Git - pkg/abook.git/commitdiff
Fixed 'undo' command corrupting the database when used after changing of
authorCedric Duval <cedricduval@free.fr>
Thu, 20 Oct 2005 13:59:30 +0000 (13:59 +0000)
committerCedric Duval <cedricduval@free.fr>
Thu, 20 Oct 2005 13:59:30 +0000 (13:59 +0000)
item within the editor.

edit.c

diff --git a/edit.c b/edit.c
index c4f17afbdc41336b202336e3968a6aeaae22319a..47c288686775c07dc89645a3ab5106bd0345edc8 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -129,11 +129,12 @@ enum {
        CLEAR_UNDO
 };
 
-static void
+static int
 edit_undo(int item, int mode)
 {
        int i;
        static list_item *backup = NULL;
+       static int backed_up_item = -1;
 
        switch(mode) {
                case CLEAR_UNDO:
@@ -154,17 +155,21 @@ edit_undo(int item, int mode)
                                else
                                        backup[0][i] =
                                                xstrdup(database[item][i]);
+                       backed_up_item = item;
                        break;
                case RESTORE_ITEM:
                        if(backup) {
-                               free_list_item(database[item]);
-                               itemcpy(database[item], backup[0]);
+                               free_list_item(database[backed_up_item]);
+                               itemcpy(database[backed_up_item], backup[0]);
                                xfree(backup);
+                               return backed_up_item;
                        }
                        break;
                default:
                        assert(0);
        }
+
+       return item;
 }
 
 
@@ -428,7 +433,7 @@ edit_loop(int item)
                case 'j': if(is_valid_item(item + 1)) item++; break;
                case 'r': roll_emails(item); break;
                case '?': display_help(HELP_EDITOR); break;
-               case 'u': edit_undo(item, RESTORE_ITEM); break;
+               case 'u': item = edit_undo(item, RESTORE_ITEM); break;
                case 'm': launch_mutt(item); clearok(stdscr, 1); break;
                case 'v': launch_wwwbrowser(item); clearok(stdscr, 1); break;
                case 12 : clearok(stdscr, 1); break; /* ^L (refresh screen) */