mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-13 05:33:51 -04:00
selection: improve handling of multi-column characters
* Don't assume multi-column characters are exactly *two* columns * Check for CELL_MULT_COL_SPACER values instead of using wcwidth()
This commit is contained in:
parent
3816a3b460
commit
1decd8e9de
1 changed files with 14 additions and 13 deletions
27
selection.c
27
selection.c
|
|
@ -375,23 +375,24 @@ selection_update(struct terminal *term, int col, int row)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle double-width characters */
|
/* If an end point is in the middle of a multi-column character,
|
||||||
|
* expand the selection to cover the entire character */
|
||||||
if (new_start.row < new_end.row ||
|
if (new_start.row < new_end.row ||
|
||||||
(new_start.row == new_end.row && new_start.col <= new_end.col))
|
(new_start.row == new_end.row && new_start.col <= new_end.col))
|
||||||
{
|
{
|
||||||
if (new_start.col - 1 >= 0)
|
while (new_start.col >= 1 &&
|
||||||
if (wcwidth(row_start->cells[new_start.col - 1].wc) > 1)
|
row_start->cells[new_start.col].wc == CELL_MULT_COL_SPACER)
|
||||||
new_start.col--;
|
new_start.col--;
|
||||||
if (new_end.col + 1 < term->cols)
|
while (new_end.col < term->cols - 1 &&
|
||||||
if (wcwidth(row_end->cells[new_end.col].wc) > 1)
|
row_end->cells[new_end.col + 1].wc == CELL_MULT_COL_SPACER)
|
||||||
new_end.col++;
|
new_end.col++;
|
||||||
} else {
|
} else {
|
||||||
if (new_end.col - 1 >= 0)
|
while (new_end.col >= 1 &&
|
||||||
if (wcwidth(row_end->cells[new_end.col - 1].wc) > 1)
|
row_end->cells[new_end.col].wc == CELL_MULT_COL_SPACER)
|
||||||
new_end.col--;
|
new_end.col--;
|
||||||
if (new_start.col + 1 < term->cols)
|
while (new_start.col < term->cols - 1 &&
|
||||||
if (wcwidth(row_start->cells[new_start.col].wc) > 1)
|
row_start->cells[new_start.col + 1].wc == CELL_MULT_COL_SPACER)
|
||||||
new_start.col++;
|
new_start.col++;
|
||||||
}
|
}
|
||||||
|
|
||||||
selection_modify(term, new_start, new_end);
|
selection_modify(term, new_start, new_end);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue