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:
Daniel Eklöf 2020-08-13 18:33:22 +02:00
parent 3816a3b460
commit 1decd8e9de
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -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);