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,39 +249,47 @@ find_word_boundary_left(struct terminal *term, struct coord *pos,
c = term->composed[c - CELL_COMB_CHARS_LO].base; c = term->composed[c - CELL_COMB_CHARS_LO].base;
} }
if (!(c != CELL_MULT_COL_SPACER && bool initial_is_space = c == 0 || iswspace(c);
(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)))) 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;
/* Linewrap */ while (true) {
if (next_col < 0) { int next_col = pos->col - 1;
next_col = term->cols - 1; int next_row = pos->row;
if (--next_row < 0)
break;
}
const struct row *row = grid_row_in_view(term->grid, next_row); /* Linewrap */
if (next_col < 0) {
next_col = term->cols - 1;
if (--next_row < 0)
break;
}
c = row->cells[next_col].wc; const struct row *row = grid_row_in_view(term->grid, next_row);
if (c >= CELL_COMB_CHARS_LO &&
c < (CELL_COMB_CHARS_LO + term->composed_count))
{
c = term->composed[c - CELL_COMB_CHARS_LO].base;
}
if (c != CELL_MULT_COL_SPACER && c = row->cells[next_col].wc;
(c == 0 || if (c >= CELL_COMB_CHARS_LO &&
!isword(c, spaces_only, term->conf->word_delimiters))) c < (CELL_COMB_CHARS_LO + term->composed_count))
{
c = term->composed[c - CELL_COMB_CHARS_LO].base;
}
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; break;
} }
pos->col = next_col;
pos->row = next_row;
} }
pos->col = next_col;
pos->row = next_row;
} }
} }
@ -298,39 +306,47 @@ find_word_boundary_right(struct terminal *term, struct coord *pos,
c = term->composed[c - CELL_COMB_CHARS_LO].base; c = term->composed[c - CELL_COMB_CHARS_LO].base;
} }
if (!(c != CELL_MULT_COL_SPACER && bool initial_is_space = c == 0 || iswspace(c);
(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters)))) 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;
/* Linewrap */ while (true) {
if (next_col >= term->cols) { int next_col = pos->col + 1;
next_col = 0; int next_row = pos->row;
if (++next_row >= term->rows)
break;
}
const struct row *row = grid_row_in_view(term->grid, next_row); /* Linewrap */
if (next_col >= term->cols) {
next_col = 0;
if (++next_row >= term->rows)
break;
}
c = row->cells[next_col].wc; const struct row *row = grid_row_in_view(term->grid, next_row);
if (c >= CELL_COMB_CHARS_LO &&
c < (CELL_COMB_CHARS_LO + term->composed_count))
{
c = term->composed[c - CELL_COMB_CHARS_LO].base;
}
if (c != CELL_MULT_COL_SPACER && c = row->cells[next_col].wc;
(c == 0 || if (c >= CELL_COMB_CHARS_LO &&
!isword(c, spaces_only, term->conf->word_delimiters))) c < (CELL_COMB_CHARS_LO + term->composed_count))
{
c = term->composed[c - CELL_COMB_CHARS_LO].base;
}
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; break;
} }
pos->col = next_col;
pos->row = next_row;
} }
pos->col = next_col;
pos->row = next_row;
} }
} }