vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit e9d4437e0c28935231de3108171ad83d6f2df9e3
parent 2d5f440acdaa5bf2d49c1bf8f9ce6fac49cdadc8
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 19 Jan 2017 10:49:02 +0100

vis: simplify count handling for insertion

Diffstat:
Mvis-core.h | 1-
Mvis-modes.c | 26+++++++++++---------------
Mvis.c | 2+-
3 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/vis-core.h b/vis-core.h @@ -160,7 +160,6 @@ 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 @@ -139,21 +139,17 @@ 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) { - /* temporarily disable motion, in something like `5atext` - * we should only move the cursor once then insert the text */ - const Movement *motion = vis->action_prev.movement; - if (motion) - vis->action_prev.movement = &vis_motions[VIS_MOVE_NOP]; - /* we already inserted the text once, so temporarily decrease count */ - vis->action_prev.count--; - vis_repeat(vis); - vis->action_prev.count++; - vis->action_prev.movement = motion; - } - vis->repeat_input = false; + if (vis->action_prev.op == &vis_operators[VIS_OP_MODESWITCH] && vis->action_prev.count > 1) { + /* temporarily disable motion, in something like `5atext` + * we should only move the cursor once then insert the text */ + const Movement *motion = vis->action_prev.movement; + if (motion) + vis->action_prev.movement = &vis_motions[VIS_MOVE_NOP]; + /* we already inserted the text once, so temporarily decrease count */ + vis->action_prev.count--; + vis_repeat(vis); + vis->action_prev.count++; + vis->action_prev.movement = motion; } /* make sure we can recover the current state after an editing operation */ vis_file_snapshot(vis, vis->win->file); diff --git a/vis.c b/vis.c @@ -1662,7 +1662,7 @@ bool vis_cmd(Vis *vis, const char *cmdline) { } void vis_file_snapshot(Vis *vis, File *file) { - if (!vis->replaying && !vis->repeat_input) + if (!vis->replaying) text_snapshot(file->text); }