Skip to content

Commit

Permalink
vis: simplify r implementation and fix cursor positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Feb 22, 2017
1 parent 75ff224 commit 75c24bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 2 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,17 +1618,9 @@ static const char *replace(Vis *vis, const char *keys, const Arg *arg) {
if (replacement[0] == 0x1b) /* <Escape> */
return next;

if (vis_mode_get(vis) == VIS_MODE_NORMAL) {
int count = vis_count_get_default(vis, 1);
vis_operator(vis, VIS_OP_CHANGE);
vis_operator(vis, VIS_OP_REPLACE, replacement);
if (vis_mode_get(vis) == VIS_MODE_OPERATOR_PENDING)
vis_motion(vis, VIS_MOVE_CHAR_NEXT);
for (; count > 0; count--)
vis_keys_feed(vis, replacement[0] == '\n' ? "<Enter>" : replacement);
} else {
vis_operator(vis, VIS_OP_REPLACE, replacement);
}

vis_keys_feed(vis, "<Escape>");
return next;
}

Expand Down
2 changes: 1 addition & 1 deletion vis-operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static size_t op_replace(Vis *vis, Text *txt, OperatorContext *c) {
size_t pos = c->range.start;
for (size_t len = strlen(c->arg->s); count > 0; pos += len, count--)
text_insert(txt, pos, c->arg->s, len);
return pos;
return c->range.start;
}

static size_t op_filter(Vis *vis, Text *txt, OperatorContext *c) {
Expand Down

0 comments on commit 75c24bb

Please sign in to comment.