selection: find_word_boundary{left,right}: what we match depends on initial character

If the initial character is a space, find the next non-space
character.

If the initial character is a delimiter, find the next non-delimiter
character (space, or word character).

If the initial character is neither (i.e, it is a word character),
find the next non-word character.
This commit is contained in:
Daniel Eklöf 2021-01-03 13:54:41 +01:00
parent 2fd7b2fbd4
commit b22091a8c9
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -249,9 +249,10 @@ find_word_boundary_left(struct terminal *term, struct coord *pos,
c = term->composed[c - CELL_COMB_CHARS_LO].base;
}
if (!(c != CELL_MULT_COL_SPACER &&
(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))))
{
bool initial_is_space = c == 0 || iswspace(c);
bool initial_is_delim = c != 0 && c != CELL_MULT_COL_SPACER &&
!isword(c, spaces_only, term->conf->word_delimiters);
while (true) {
int next_col = pos->col - 1;
int next_row = pos->row;
@ -272,17 +273,24 @@ find_word_boundary_left(struct terminal *term, struct coord *pos,
c = term->composed[c - CELL_COMB_CHARS_LO].base;
}
if (c != CELL_MULT_COL_SPACER &&
(c == 0 ||
!isword(c, spaces_only, term->conf->word_delimiters)))
bool is_space = c == 0 || iswspace(c);
if (initial_is_space && !is_space)
break;
if (!initial_is_space) {
bool is_word = c != 0 && c != CELL_MULT_COL_SPACER &&
isword(c, spaces_only, term->conf->word_delimiters);
if ((initial_is_delim && (is_word || is_space)) ||
(!initial_is_delim && !is_word))
{
break;
}
}
pos->col = next_col;
pos->row = next_row;
}
}
}
static void
@ -298,9 +306,10 @@ find_word_boundary_right(struct terminal *term, struct coord *pos,
c = term->composed[c - CELL_COMB_CHARS_LO].base;
}
if (!(c != CELL_MULT_COL_SPACER &&
(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))))
{
bool initial_is_space = c == 0 || iswspace(c);
bool initial_is_delim = c != 0 && c != CELL_MULT_COL_SPACER &&
!isword(c, spaces_only, term->conf->word_delimiters);
while (true) {
int next_col = pos->col + 1;
int next_row = pos->row;
@ -321,17 +330,24 @@ find_word_boundary_right(struct terminal *term, struct coord *pos,
c = term->composed[c - CELL_COMB_CHARS_LO].base;
}
if (c != CELL_MULT_COL_SPACER &&
(c == 0 ||
!isword(c, spaces_only, term->conf->word_delimiters)))
bool is_space = c == 0 || iswspace(c);
if (initial_is_space && !is_space)
break;
if (!initial_is_space) {
bool is_word = c != 0 && c != CELL_MULT_COL_SPACER &&
isword(c, spaces_only, term->conf->word_delimiters);
if ((initial_is_delim && (is_word || is_space)) ||
(!initial_is_delim && !is_word))
{
break;
}
}
pos->col = next_col;
pos->row = next_row;
}
}
}
void