aboutsummaryrefslogtreecommitdiff
path: root/vt.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-06-15 05:25:38 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-06-24 15:30:46 +0000
commit09431dd15c0e5d67adde766deb5f685a2918bb18 (patch)
tree7a775f08378a63ff95f7a6557dc0abe8a99d8479 /vt.c
parentrender: repair parenthesis after rebase (diff)
vt: presentation selectors may be anywhere in the cluster
Diffstat (limited to 'vt.c')
-rw-r--r--vt.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/vt.c b/vt.c
index aff3131b..c343ba14 100644
--- a/vt.c
+++ b/vt.c
@@ -726,20 +726,22 @@ action_utf8_print(struct terminal *term, wchar_t wc)
struct composed new_cc;
new_cc.count = wanted_count;
new_cc.chars[0] = base;
+
for (size_t i = 1; i < wanted_count - 1; i++)
new_cc.chars[i] = composed->chars[i];
new_cc.chars[wanted_count - 1] = wc;
if (term->composed_count < CELL_COMB_CHARS_HI) {
- /* TODO: grapheme cluster width */
- int grapheme_width = wcswidth(new_cc.chars, new_cc.count);
-#if 0 /* Fish expects this, but nothing else */
- if (new_cc.chars[new_cc.count - 1] == 0xfe0f) {
- /* Emoji selector */
- grapheme_width = max(2, grapheme_width);
+ int grapheme_width = wcwidth(base);
+ int min_grapheme_width = 0;
+ for (size_t i = 0; i < wanted_count; i++) {
+ wchar_t c = new_cc.chars[i];
+ if (c == 0xfe0f)
+ min_grapheme_width = 2;
+ grapheme_width += wcwidth(c);
}
-#endif
- new_cc.width = grapheme_width;
+
+ new_cc.width = max(grapheme_width, min_grapheme_width);
term->composed_count++;
term->composed = xrealloc(term->composed, term->composed_count * sizeof(term->composed[0]));