aboutsummaryrefslogtreecommitdiff
path: root/text-objects.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2020-08-31 22:10:38 +0200
committerMarc André Tanner <mat@brain-dump.org>2020-08-31 22:51:40 +0200
commit1b9d70eafc24eaa82c2796fa6d72a482bb09dba9 (patch)
treeb690455a10d49b08a3b5413ab3c68f83bed872c5 /text-objects.c
parent4b2aa76ea98f9219b46a775f393955b4fdb23cbd (diff)
downloadvis-1b9d70eafc24eaa82c2796fa6d72a482bb09dba9.tar.gz
vis-1b9d70eafc24eaa82c2796fa6d72a482bb09dba9.tar.xz
text: improve and simplify inner word text object
Previously words ending in special symbols would wrongly be included in range.
Diffstat (limited to 'text-objects.c')
-rw-r--r--text-objects.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/text-objects.c b/text-objects.c
index 7cedd3f..fb5adc2 100644
--- a/text-objects.c
+++ b/text-objects.c
@@ -27,33 +27,26 @@ static Filerange text_object_customword(Text *txt, size_t pos, int (*isboundary)
if (space(c)) {
r.start = text_char_next(txt, text_customword_end_prev(txt, pos, isboundary));
r.end = text_customword_start_next(txt, pos, isboundary);
- } else if (boundary(prev) && boundary(next)) {
- if ((space(prev) && space(next)) || !boundary(c)) {
- /* on a single character */
+ } else if (boundary(c)) {
+ if (boundary(prev) && !space(prev))
+ r.start = text_customword_start_prev(txt, pos, isboundary);
+ else
r.start = pos;
+
+ if (boundary(next) && !space(next))
+ r.end = text_char_next(txt, text_customword_end_next(txt, pos, isboundary));
+ else
r.end = text_char_next(txt, pos);
- } else if (space(prev)) {
+ } else {
+ if (boundary(prev))
r.start = pos;
- r.end = text_char_next(txt, text_customword_end_next(txt, pos, isboundary));
- } else if (space(next)) {
+ else
r.start = text_customword_start_prev(txt, pos, isboundary);
+
+ if (boundary(next))
r.end = text_char_next(txt, pos);
- } else {
- r.start = text_customword_start_prev(txt, pos, isboundary);
+ else
r.end = text_char_next(txt, text_customword_end_next(txt, pos, isboundary));
- }
- } else if (boundary(prev)) {
- /* at start of a word */
- r.start = pos;
- r.end = text_char_next(txt, text_customword_end_next(txt, pos, isboundary));
- } else if (boundary(next)) {
- /* at end of a word */
- r.start = text_customword_start_prev(txt, pos, isboundary);
- r.end = text_char_next(txt, pos);
- } else {
- /* in the middle of a word */
- r.start = text_customword_start_prev(txt, pos, isboundary);
- r.end = text_char_next(txt, text_customword_end_next(txt, pos, isboundary));
}
return r;