aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-08-13 16:33:22 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-08-13 16:33:22 +0000
commit1decd8e9ded3ff9ea6af2226ce85a3fad9731399 (patch)
tree9e10106eaf957f7f75cf4d3a710252704344aca2
parentselection: handle multi-column characters when reversing selection direction (diff)
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()
-rw-r--r--selection.c27
1 files 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);