diff options
| -rw-r--r-- | main.c | 12 | ||||
| -rw-r--r-- | vis-core.h | 1 | ||||
| -rw-r--r-- | vis-modes.c | 11 | ||||
| -rw-r--r-- | vis.c | 2 |
4 files changed, 22 insertions, 4 deletions
@@ -33,6 +33,8 @@ static const char *suspend(Vis*, const char *keys, const Arg *arg); static const char *switchmode(Vis*, const char *keys, const Arg *arg); /* switch to insert mode after performing movement indicated by arg->i */ static const char *insertmode(Vis*, const char *keys, const Arg *arg); +/* switch to replace mode after performing movement indicated by arg->i */ +static const char *replacemode(Vis*, const char *keys, const Arg *arg); /* set mark indicated by keys to current cursor position */ static const char *mark_set(Vis*, const char *keys, const Arg *arg); /* add a new line either before or after the one where the cursor currently is */ @@ -617,12 +619,12 @@ static const KeyAction vis_action[] = { [VIS_ACTION_MODE_INSERT] = { "vis-mode-insert", "Enter insert mode", - switchmode, { .i = VIS_MODE_INSERT } + insertmode, { .i = VIS_MOVE_NOP } }, [VIS_ACTION_MODE_REPLACE] = { "vis-mode-replace", "Enter replace mode", - switchmode, { .i = VIS_MODE_REPLACE } + replacemode, { .i = VIS_MOVE_NOP } }, [VIS_ACTION_MODE_OPERATOR_PENDING] = { "vis-mode-operator-pending", @@ -2006,6 +2008,12 @@ static const char *insertmode(Vis *vis, const char *keys, const Arg *arg) { return keys; } +static const char *replacemode(Vis *vis, const char *keys, const Arg *arg) { + vis_operator(vis, VIS_OP_MODESWITCH, VIS_MODE_REPLACE); + vis_motion(vis, arg->i); + return keys; +} + static const char *unicode_info(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); Text *txt = vis_text(vis); @@ -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 */ + bool repeat_input; /* true while processing count for insertion/replacement */ 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 */ diff --git a/vis-modes.c b/vis-modes.c index a82c71b..6f861d9 100644 --- a/vis-modes.c +++ b/vis-modes.c @@ -138,9 +138,18 @@ bool vis_window_mode_map(Win *win, enum VisMode id, bool force, const char *key, static void vis_mode_normal_enter(Vis *vis, Mode *old) { if (old != mode_get(vis, VIS_MODE_INSERT) && old != mode_get(vis, VIS_MODE_REPLACE)) return; + macro_operator_stop(vis); + if (vis->action_prev.op == &vis_operators[VIS_OP_MODESWITCH] && !vis->repeat_input) { + vis->repeat_input = true; + if (vis->action_prev.count > 1) { + vis->action_prev.count--; + vis_repeat(vis); + vis->action_prev.count++; + } + vis->repeat_input = false; + } /* make sure we can recover the current state after an editing operation */ vis_file_snapshot(vis, vis->win->file); - macro_operator_stop(vis); } static void vis_mode_operator_input(Vis *vis, const char *str, size_t len) { @@ -1660,7 +1660,7 @@ bool vis_cmd(Vis *vis, const char *cmdline) { } void vis_file_snapshot(Vis *vis, File *file) { - if (!vis->replaying) + if (!vis->replaying && !vis->repeat_input) text_snapshot(file->text); } |
