summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston2021-04-06 13:41:01 +0100
committerDenys Vlasenko2021-04-11 00:18:55 +0200
commite577afca7c94a7827bc216f4d8c95823d0f86489 (patch)
tree994214910b4c1d6fd542215b474577672814bb88
parentb7b1119d9f95cc956eb0161a59ee21a1daca8f52 (diff)
downloadbusybox-e577afca7c94a7827bc216f4d8c95823d0f86489.zip
busybox-e577afca7c94a7827bc216f4d8c95823d0f86489.tar.gz
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.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 9a17f65..7e89f58 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -3117,8 +3117,10 @@ static int find_range(char **start, char **stop, int cmd)
} else if (strchr("wW", c)) {
buftype = MULTI;
do_cmd(c); // execute movement cmd
- // step back one char, but not if we're at end of file
- if (dot > p && !at_eof(dot))
+ // step back one char, but not if we're at end of file,
+ // or if we are at EOF and search was for 'w' and we're at
+ // the start of a 'W' word.
+ if (dot > p && (!at_eof(dot) || (c == 'w' && ispunct(*dot))))
dot--;
t = dot;
// don't include trailing WS as part of word
@@ -3127,7 +3129,7 @@ static int find_range(char **start, char **stop, int cmd)
t = dot;
}
// for non-change operations WS after NL is not part of word
- if (cmd != 'c' && dot != p && *dot != '\n')
+ if (cmd != 'c' && dot != t && *dot != '\n')
dot = t;
} else if (strchr("GHL+-jk'\r\n", c)) {
// these operate on whole lines