From 1decd8e9ded3ff9ea6af2226ce85a3fad9731399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 13 Aug 2020 18:33:22 +0200 Subject: [PATCH] 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() --- selection.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/selection.c b/selection.c index 605e4cf5..a078a698 100644 --- a/selection.c +++ b/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 || (new_start.row == new_end.row && new_start.col <= new_end.col)) { - if (new_start.col - 1 >= 0) - if (wcwidth(row_start->cells[new_start.col - 1].wc) > 1) - new_start.col--; - if (new_end.col + 1 < term->cols) - if (wcwidth(row_end->cells[new_end.col].wc) > 1) - new_end.col++; + while (new_start.col >= 1 && + row_start->cells[new_start.col].wc == CELL_MULT_COL_SPACER) + new_start.col--; + while (new_end.col < term->cols - 1 && + row_end->cells[new_end.col + 1].wc == CELL_MULT_COL_SPACER) + new_end.col++; } else { - if (new_end.col - 1 >= 0) - if (wcwidth(row_end->cells[new_end.col - 1].wc) > 1) - new_end.col--; - if (new_start.col + 1 < term->cols) - if (wcwidth(row_start->cells[new_start.col].wc) > 1) - new_start.col++; + while (new_end.col >= 1 && + row_end->cells[new_end.col].wc == CELL_MULT_COL_SPACER) + new_end.col--; + while (new_start.col < term->cols - 1 && + row_start->cells[new_start.col + 1].wc == CELL_MULT_COL_SPACER) + new_start.col++; } selection_modify(term, new_start, new_end);