aboutsummaryrefslogtreecommitdiff
path: root/selection.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-03 13:33:35 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-04 18:48:42 +0000
commitc851aae9d6107e310232fbc18cdf7ffea2a9bf46 (patch)
tree83d5d5f61f125de33b6f0c5a3cb126e1c37a052f /selection.c
parentselection: find_word_boundary_{left,right}: handle multi-column characters (diff)
selection: find_word_boundary_{left,right}: try to make the code more readable
Diffstat (limited to 'selection.c')
-rw-r--r--selection.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/selection.c b/selection.c
index cb154477..df643486 100644
--- a/selection.c
+++ b/selection.c
@@ -259,7 +259,9 @@ find_word_boundary_left(struct terminal *term, struct coord *pos,
bool initial_is_space = c == 0 || iswspace(c);
bool initial_is_delim =
- c != 0 && !isword(c, spaces_only, term->conf->word_delimiters);
+ !initial_is_space && !isword(c, spaces_only, term->conf->word_delimiters);
+ bool initial_is_word =
+ c != 0 && isword(c, spaces_only, term->conf->word_delimiters);
while (true) {
int next_col = pos->col - 1;
@@ -289,19 +291,17 @@ find_word_boundary_left(struct terminal *term, struct coord *pos,
}
bool is_space = c == 0 || iswspace(c);
+ bool is_delim =
+ !is_space && !isword(c, spaces_only, term->conf->word_delimiters);
+ bool is_word =
+ c != 0 && isword(c, spaces_only, term->conf->word_delimiters);
+
if (initial_is_space && !is_space)
break;
-
- if (!initial_is_space) {
- bool is_word =
- c != 0 && isword(c, spaces_only, term->conf->word_delimiters);
-
- if ((initial_is_delim && (is_word || is_space)) ||
- (!initial_is_delim && !is_word))
- {
- break;
- }
- }
+ if (initial_is_delim && !is_delim)
+ break;
+ if (initial_is_word && !is_word)
+ break;
pos->col = next_col;
pos->row = next_row;
@@ -331,7 +331,9 @@ find_word_boundary_right(struct terminal *term, struct coord *pos,
bool initial_is_space = c == 0 || iswspace(c);
bool initial_is_delim =
- c != 0 && !isword(c, spaces_only, term->conf->word_delimiters);
+ !initial_is_space && !isword(c, spaces_only, term->conf->word_delimiters);
+ bool initial_is_word =
+ c != 0 && isword(c, spaces_only, term->conf->word_delimiters);
while (true) {
int next_col = pos->col + 1;
@@ -363,19 +365,17 @@ find_word_boundary_right(struct terminal *term, struct coord *pos,
}
bool is_space = c == 0 || iswspace(c);
+ bool is_delim =
+ !is_space && !isword(c, spaces_only, term->conf->word_delimiters);
+ bool is_word =
+ c != 0 && isword(c, spaces_only, term->conf->word_delimiters);
+
if (initial_is_space && !is_space)
break;
-
- if (!initial_is_space) {
- bool is_word =
- c != 0 && isword(c, spaces_only, term->conf->word_delimiters);
-
- if ((initial_is_delim && (is_word || is_space)) ||
- (!initial_is_delim && !is_word))
- {
- break;
- }
- }
+ if (initial_is_delim && !is_delim)
+ break;
+ if (initial_is_word && !is_word)
+ break;
pos->col = next_col;
pos->row = next_row;