diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-09-08 21:58:50 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-09-08 21:58:50 +0200 |
| commit | ee3ded959f5486e921e45ac6753b21c2fcd63f0f (patch) | |
| tree | 69bbccd4f7babce44dad355ac0dcc1573e9fa895 /config.def.h | |
| parent | e7b6ac1574ba4dad280e6a45beb52dac4e3ea2e9 (diff) | |
| download | vis-ee3ded959f5486e921e45ac6753b21c2fcd63f0f.tar.gz vis-ee3ded959f5486e921e45ac6753b21c2fcd63f0f.tar.xz | |
Improve undo/redo
Currently a snapshot is taken whenever an operator is completed or
a certain idle time in either insert or replace mode is detected.
Diffstat (limited to 'config.def.h')
| -rw-r--r-- | config.def.h | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/config.def.h b/config.def.h index 3b5437e..6ab2286 100644 --- a/config.def.h +++ b/config.def.h @@ -288,6 +288,10 @@ static void split(const Arg *arg) { void action_do(Action *a); void action_reset(Action *a); +static void snapshot(void) { + text_snapshot(vis->win->text); +} + static void repeat(const Arg *arg) { action = action_prev; action_do(&action); @@ -457,6 +461,7 @@ void action_do(Action *a) { switchmode_to(mode_prev); else if (mode == &vis_modes[VIS_MODE_VISUAL]) switchmode(&(const Arg){ .i = VIS_MODE_NORMAL }); + snapshot(); } if (a != &action_prev) { @@ -466,6 +471,16 @@ void action_do(Action *a) { } } +static void undo(const Arg *arg) { + if (text_undo(vis->win->text)) + vis_draw(vis); +} + +static void redo(const Arg *arg) { + if (text_redo(vis->win->text)) + vis_draw(vis); +} + static void zero(const Arg *arg) { if (action.count == 0) movement(&(const Arg){ .i = MOVE_LINE_BEGIN }); @@ -698,8 +713,8 @@ static KeyBinding vis_normal[] = { { { NONE('i') }, switchmode, { .i = VIS_MODE_INSERT } }, { { NONE('v') }, switchmode, { .i = VIS_MODE_VISUAL } }, { { NONE('R') }, switchmode, { .i = VIS_MODE_REPLACE} }, - { { NONE('u') }, call, { .f = vis_undo } }, - { { CONTROL('R') }, call, { .f = vis_redo } }, + { { NONE('u') }, undo, { NULL } }, + { { CONTROL('R') }, redo, { NULL } }, { { CONTROL('L') }, call, { .f = vis_draw } }, { { NONE(':') }, prompt, { .s = ":" } }, { /* empty last element, array terminator */ }, @@ -862,12 +877,14 @@ static Mode vis_modes[] = { .parent = &vis_modes[VIS_MODE_READLINE], .bindings = vis_insert_mode, .input = vis_insert_input, + .idle = snapshot, }, [VIS_MODE_REPLACE] = { .name = "REPLACE", .parent = &vis_modes[VIS_MODE_INSERT], .bindings = vis_replace, .input = vis_replace_input, + .idle = snapshot, }, }; @@ -939,8 +956,8 @@ static KeyBinding nano_keys[] = { { { META('|') }, movement, { .i = MOVE_FILE_BEGIN } }, { { META('/') }, movement, { .i = MOVE_FILE_END } }, { { META('?') }, movement, { .i = MOVE_FILE_END } }, - { { META('U') }, call, { .f = vis_undo } }, - { { META('E') }, call, { .f = vis_redo } }, + { { META('U') }, undo, { NULL } }, + { { META('E') }, redo, { NULL } }, #if 0 { { CONTROL('I') }, insert, { .s = "\t" } }, /* TODO: handle this in vis to insert \n\r when appriopriate */ |
