diff options
author | Ron Yorston <rmy@pobox.com> | 2021-02-01 11:54:15 +0000 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-02-02 14:41:55 +0100 |
commit | 5bef6781fa434bd65558cefe950f670df34fea4e (patch) | |
tree | 4957968c32ac7b8ca32497d95e5e1ee57f39cca7 | |
parent | bcf91d276047910538c5de0a45f3a4645e3ff471 (diff) | |
download | busybox-w32-5bef6781fa434bd65558cefe950f670df34fea4e.tar.gz busybox-w32-5bef6781fa434bd65558cefe950f670df34fea4e.tar.bz2 busybox-w32-5bef6781fa434bd65558cefe950f670df34fea4e.zip |
vi: fix range selection by forward character motion
Selection of ranges for change/delete/yank by forward character
motion commands (SPACE or 'l') was incorrect. The range was
always one character whereas vi allows the size of the range to
be specified.
Fix this by executing the motion command the required number of times.
There is a complication when the range is at the end of a line. We need
to distinguish between a range which excludes the last character and
one which includes it. This requires comparing the actual range with
that expected from the command count. (With the additional quirk that
a command count of zero is equivalent to a command count of one.)
function old new delta
find_range 587 619 +32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 32/0) Total: 32 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/vi.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/editors/vi.c b/editors/vi.c index 01597fa5e..adfb2b87c 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -3047,12 +3047,15 @@ static int find_range(char **start, char **stop, char c) | |||
3047 | do_cmd(c); // execute movement cmd | 3047 | do_cmd(c); // execute movement cmd |
3048 | dot_end(); // find NL | 3048 | dot_end(); // find NL |
3049 | q = dot; | 3049 | q = dot; |
3050 | } else { | 3050 | } else /* if (c == ' ' || c == 'l') */ { |
3051 | // nothing -- this causes any other values of c to | 3051 | // forward motion by character |
3052 | // represent the one-character range under the | 3052 | int tmpcnt = (cmdcnt ?: 1); |
3053 | // cursor. this is correct for ' ' and 'l', but | 3053 | do_cmd(c); // execute movement cmd |
3054 | // perhaps no others. | 3054 | // exclude last char unless range isn't what we expected |
3055 | // | 3055 | // this indicates we've hit EOL |
3056 | if (tmpcnt == dot - p) | ||
3057 | dot--; | ||
3058 | q = dot; | ||
3056 | } | 3059 | } |
3057 | if (q < p) { | 3060 | if (q < p) { |
3058 | t = q; | 3061 | t = q; |