mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-17 05:33:52 -04:00
selection: add a couple of word-breaking characters
When "auto-selecting" a word, we used to only break on space characters. Now we break on a number of other characters as well.
This commit is contained in:
parent
c03aeb1b4f
commit
b82dc02505
1 changed files with 22 additions and 4 deletions
26
selection.c
26
selection.c
|
|
@ -213,6 +213,24 @@ selection_cancel(struct terminal *term)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
isword(int c)
|
||||||
|
{
|
||||||
|
switch (c) {
|
||||||
|
default: return !isspace(c);
|
||||||
|
|
||||||
|
case '{': case '}':
|
||||||
|
case '[': case ']':
|
||||||
|
case '(': case ')':
|
||||||
|
case '`':
|
||||||
|
case '\'':
|
||||||
|
case '"':
|
||||||
|
case ',': case '.':
|
||||||
|
case ':': case ';':
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
|
selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
|
||||||
{
|
{
|
||||||
|
|
@ -227,7 +245,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
|
||||||
const struct row *r = grid_row_in_view(term->grid, start.row);
|
const struct row *r = grid_row_in_view(term->grid, start.row);
|
||||||
unsigned char c = r->cells[start.col].c[0];
|
unsigned char c = r->cells[start.col].c[0];
|
||||||
|
|
||||||
if (!(c == '\0' || isspace(c))) {
|
if (!(c == '\0' || !isword(c))) {
|
||||||
while (true) {
|
while (true) {
|
||||||
int next_col = start.col - 1;
|
int next_col = start.col - 1;
|
||||||
int next_row = start.row;
|
int next_row = start.row;
|
||||||
|
|
@ -242,7 +260,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
|
||||||
const struct row *row = grid_row_in_view(term->grid, next_row);
|
const struct row *row = grid_row_in_view(term->grid, next_row);
|
||||||
|
|
||||||
unsigned char c = row->cells[next_col].c[0];
|
unsigned char c = row->cells[next_col].c[0];
|
||||||
if (c == '\0' || isspace(c))
|
if (c == '\0' || !isword(c))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
start.col = next_col;
|
start.col = next_col;
|
||||||
|
|
@ -253,7 +271,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
|
||||||
r = grid_row_in_view(term->grid, end.row);
|
r = grid_row_in_view(term->grid, end.row);
|
||||||
c = r->cells[end.col].c[0];
|
c = r->cells[end.col].c[0];
|
||||||
|
|
||||||
if (!(c == '\0' || isspace(c))) {
|
if (!(c == '\0' || !isword(c))) {
|
||||||
while (true) {
|
while (true) {
|
||||||
int next_col = end.col + 1;
|
int next_col = end.col + 1;
|
||||||
int next_row = end.row;
|
int next_row = end.row;
|
||||||
|
|
@ -268,7 +286,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
|
||||||
const struct row *row = grid_row_in_view(term->grid, next_row);
|
const struct row *row = grid_row_in_view(term->grid, next_row);
|
||||||
|
|
||||||
unsigned char c = row->cells[next_col].c[0];
|
unsigned char c = row->cells[next_col].c[0];
|
||||||
if (c == '\0' || isspace(c))
|
if (c == '\0' || !isword(c))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
end.col = next_col;
|
end.col = next_col;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue