diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-12-29 22:42:58 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-01-18 12:53:13 +0100 |
| commit | fb7f934204035b1e02c8394eee5c8b1df5e476ec (patch) | |
| tree | 0a42b20835fb7fe3cd31e28cb4c26d393a977f81 /vis.c | |
| parent | 9997739b96a7fc142a18cb72cb7589bd4b4d61b0 (diff) | |
| download | vis-fb7f934204035b1e02c8394eee5c8b1df5e476ec.tar.gz vis-fb7f934204035b1e02c8394eee5c8b1df5e476ec.tar.xz | |
vis: do not take undo snaphots while replaying a macro
The vis_keys_feed function is currently unaffected by this change.
It still creates individual undo points. While this is probably
undesirable from an API point of view, it keeps the lua based tests
that use undo points working.
Diffstat (limited to 'vis.c')
| -rw-r--r-- | vis.c | 27 |
1 files changed, 22 insertions, 5 deletions
@@ -56,6 +56,7 @@ const RegisterDef vis_registers[] = { static Macro *macro_get(Vis *vis, enum VisRegister); static void macro_replay(Vis *vis, const Macro *macro); +static void macro_replay_internal(Vis *vis, const Macro *macro); static void vis_keys_push(Vis *vis, const char *input, size_t pos, bool record); bool vis_event_emit(Vis *vis, enum VisEvents id, ...) { @@ -673,7 +674,8 @@ static void window_jumplist_invalidate(Win *win) { void vis_do(Vis *vis) { Win *win = vis->win; - Text *txt = win->file->text; + File *file = win->file; + Text *txt = file->text; View *view = win->view; Action *a = &vis->action; @@ -693,7 +695,7 @@ void vis_do(Vis *vis) { size_t pos = view_cursors_pos(cursor); Register *reg = multiple_cursors ? view_cursors_register(cursor) : a->reg; if (!reg) - reg = &vis->registers[win->file->internal ? VIS_REG_PROMPT : VIS_REG_DEFAULT]; + reg = &vis->registers[file->internal ? VIS_REG_PROMPT : VIS_REG_DEFAULT]; OperatorContext c = { .count = count, @@ -714,7 +716,7 @@ void vis_do(Vis *vis) { else if (a->movement->cur) pos = a->movement->cur(cursor); else if (a->movement->file) - pos = a->movement->file(vis, vis->win->file, pos); + pos = a->movement->file(vis, file, pos); else if (a->movement->vis) pos = a->movement->vis(vis, txt, pos); else if (a->movement->view) @@ -844,7 +846,7 @@ void vis_do(Vis *vis) { } if (vis->mode == &vis_modes[VIS_MODE_NORMAL]) - text_snapshot(txt); + vis_file_snapshot(vis, file); vis_draw(vis); } @@ -1038,7 +1040,8 @@ void vis_keys_feed(Vis *vis, const char *input) { macro_init(¯o); if (!macro_append(¯o, input)) return; - macro_replay(vis, ¯o); + /* use internal function, to keep Lua based tests which use undo points working */ + macro_replay_internal(vis, ¯o); macro_release(¯o); } @@ -1230,6 +1233,13 @@ bool vis_macro_recording(Vis *vis) { } static void macro_replay(Vis *vis, const Macro *macro) { + const Macro *replaying = vis->replaying; + vis->replaying = macro; + macro_replay_internal(vis, macro); + vis->replaying = replaying; +} + +static void macro_replay_internal(Vis *vis, const Macro *macro) { size_t pos = buffer_length0(vis->keys); for (char *key = macro->data, *next; key; key = next) { char tmp; @@ -1258,6 +1268,7 @@ bool vis_macro_replay(Vis *vis, enum VisRegister id) { if (!macro || macro == vis->recording) return false; macro_replay(vis, macro); + vis_file_snapshot(vis, vis->win->file); return true; } @@ -1293,6 +1304,7 @@ void vis_repeat(Vis *vis) { vis->action_prev = action_prev; } vis_cancel(vis); + vis_file_snapshot(vis, vis->win->file); } enum VisMark vis_mark_from(Vis *vis, char mark) { @@ -1644,6 +1656,11 @@ bool vis_cmd(Vis *vis, const char *cmdline) { return err == SAM_ERR_OK; } +void vis_file_snapshot(Vis *vis, File *file) { + if (!vis->replaying) + text_snapshot(file->text); +} + Text *vis_text(Vis *vis) { return vis->win->file->text; } |
