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 | |
| 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.
| -rw-r--r-- | vis-core.h | 1 | ||||
| -rw-r--r-- | vis-modes.c | 6 | ||||
| -rw-r--r-- | vis.c | 27 | ||||
| -rw-r--r-- | vis.h | 3 |
4 files changed, 29 insertions, 8 deletions
@@ -160,6 +160,7 @@ struct Vis { Win *message_window; /* special window to display multi line messages */ Register registers[VIS_REG_INVALID]; /* registers used for text manipulations yank/put etc. and macros */ Macro *recording, *last_recording; /* currently (if non NULL) and least recently recorded macro */ + const Macro *replaying; /* macro currently being replayed */ Macro *macro_operator; /* special macro used to repeat certain operators */ Mode *mode_before_prompt; /* user mode which was active before entering prompt */ char search_char[8]; /* last used character to search for via 'f', 'F', 't', 'T' */ diff --git a/vis-modes.c b/vis-modes.c index 8df7b16..c3ade9f 100644 --- a/vis-modes.c +++ b/vis-modes.c @@ -190,13 +190,13 @@ static void vis_mode_insert_enter(Vis *vis, Mode *old) { static void vis_mode_insert_leave(Vis *vis, Mode *new) { if (new == mode_get(vis, VIS_MODE_NORMAL)) { /* make sure we can recover the current state after an editing operation */ - text_snapshot(vis->win->file->text); + vis_file_snapshot(vis, vis->win->file); macro_operator_stop(vis); } } static void vis_mode_insert_idle(Vis *vis) { - text_snapshot(vis->win->file->text); + vis_file_snapshot(vis, vis->win->file); } static void vis_mode_insert_input(Vis *vis, const char *str, size_t len) { @@ -220,7 +220,7 @@ static void vis_mode_replace_enter(Vis *vis, Mode *old) { static void vis_mode_replace_leave(Vis *vis, Mode *new) { if (new == mode_get(vis, VIS_MODE_NORMAL)) { /* make sure we can recover the current state after an editing operation */ - text_snapshot(vis->win->file->text); + vis_file_snapshot(vis, vis->win->file); macro_operator_stop(vis); } } @@ -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; } @@ -120,6 +120,9 @@ bool vis_window_syntax_set(Win*, const char *name); int vis_window_width_get(const Win*); int vis_window_height_get(const Win*); +/* take an undo snaphost to which we can later revert to */ +void vis_file_snapshot(Vis*, File*); + /* display a user prompt with a certain title and default text */ void vis_prompt_show(Vis*, const char *title); |
