diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-02-22 11:22:13 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-02-22 12:42:19 +0100 |
| commit | 75c24bb43ccbc0907eb427a44330e66986601f88 (patch) | |
| tree | 46bf504e528d9d83ae0f61c4a725f88d9ab5622b | |
| parent | 75ff22469b21e72a4c9126d89cfa3623af1784fd (diff) | |
| download | vis-75c24bb43ccbc0907eb427a44330e66986601f88.tar.gz vis-75c24bb43ccbc0907eb427a44330e66986601f88.tar.xz | |
vis: simplify `r` implementation and fix cursor positioning
| -rw-r--r-- | main.c | 12 | ||||
| -rw-r--r-- | vis-operators.c | 2 |
2 files changed, 3 insertions, 11 deletions
@@ -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; } diff --git a/vis-operators.c b/vis-operators.c index 2a51b2f..2ffed01 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -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) { |
