From: Cedric Duval Date: Thu, 20 Oct 2005 13:59:30 +0000 (+0000) Subject: Fixed 'undo' command corrupting the database when used after changing of X-Git-Tag: upstream/0.6.1~2^2~131 X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=99466f28c5688cca384f3c9830688773bf7c9a8e;p=pkg%2Fabook.git Fixed 'undo' command corrupting the database when used after changing of item within the editor. --- diff --git a/edit.c b/edit.c index c4f17af..47c2886 100644 --- 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) */