diff options
author | Ron Yorston <rmy@pobox.com> | 2021-04-06 13:41:01 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-04-11 00:18:55 +0200 |
commit | e577afca7c94a7827bc216f4d8c95823d0f86489 (patch) | |
tree | 994214910b4c1d6fd542215b474577672814bb88 | |
parent | b7b1119d9f95cc956eb0161a59ee21a1daca8f52 (diff) | |
download | busybox-w32-e577afca7c94a7827bc216f4d8c95823d0f86489.tar.gz busybox-w32-e577afca7c94a7827bc216f4d8c95823d0f86489.tar.bz2 busybox-w32-e577afca7c94a7827bc216f4d8c95823d0f86489.zip |
vi: more fixes to range selection by word
An example in my vi book presents different ways to fix the spelling
of the last word in a line:
... anyweigh.
With the cursor on the 'e' the command 'cway' should do the job.
Since commit 776b56d77, though, 'cw' incorrectly includes the full
stop in the range if we're on the last line of the file.
(Prior to commit 776b56d77 BusyBox vi got 'cw' right in this case but
'cW' wrong: it *didn't* delete the full stop.)
Reinstate some of the bloat removed by the earlier commit to fix this.
Also, commit 7b4c2276a (vi: fix word operations across line boundaries)
incorrectly ignores whitespace after a single character word. Adjust
the condition to avoid this.
function old new delta
find_range 707 737 +30
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 30/0) Total: 30 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/vi.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/editors/vi.c b/editors/vi.c index 9a17f6527..7e89f58da 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -3117,8 +3117,10 @@ static int find_range(char **start, char **stop, int cmd) | |||
3117 | } else if (strchr("wW", c)) { | 3117 | } else if (strchr("wW", c)) { |
3118 | buftype = MULTI; | 3118 | buftype = MULTI; |
3119 | do_cmd(c); // execute movement cmd | 3119 | do_cmd(c); // execute movement cmd |
3120 | // step back one char, but not if we're at end of file | 3120 | // step back one char, but not if we're at end of file, |
3121 | if (dot > p && !at_eof(dot)) | 3121 | // or if we are at EOF and search was for 'w' and we're at |
3122 | // the start of a 'W' word. | ||
3123 | if (dot > p && (!at_eof(dot) || (c == 'w' && ispunct(*dot)))) | ||
3122 | dot--; | 3124 | dot--; |
3123 | t = dot; | 3125 | t = dot; |
3124 | // don't include trailing WS as part of word | 3126 | // don't include trailing WS as part of word |
@@ -3127,7 +3129,7 @@ static int find_range(char **start, char **stop, int cmd) | |||
3127 | t = dot; | 3129 | t = dot; |
3128 | } | 3130 | } |
3129 | // for non-change operations WS after NL is not part of word | 3131 | // for non-change operations WS after NL is not part of word |
3130 | if (cmd != 'c' && dot != p && *dot != '\n') | 3132 | if (cmd != 'c' && dot != t && *dot != '\n') |
3131 | dot = t; | 3133 | dot = t; |
3132 | } else if (strchr("GHL+-jk'\r\n", c)) { | 3134 | } else if (strchr("GHL+-jk'\r\n", c)) { |
3133 | // these operate on whole lines | 3135 | // these operate on whole lines |