From 88dcde3ed8b30c14a5d834d0e88f9b4a5f584939 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 6 Feb 2025 07:31:30 +0100 Subject: term: insert-mode: handle combining characters correctly When the client application emits combining characters, for example multi-codepoint emojis, in insert-mode, we ended up pushing partial graphemes to the right, for each codepoint, resulting in too many cells (and with the wrong content) being inserted. The fix is fairly simple; don't "insert" when appending characters to an existing grapheme cluster. This isn't something we can detect easily in print_insert() (it would require us to do grapheme clustering again). Fortunately, we do have the required information in action_utf8_print(). So, pass this information as a boolean to term_print(). Closes #1947 --- terminal.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 9fd20002..b88a794e 100644 --- a/terminal.c +++ b/terminal.c @@ -3896,7 +3896,7 @@ term_fill(struct terminal *term, int r, int c, uint8_t data, size_t count, } void -term_print(struct terminal *term, char32_t wc, int width) +term_print(struct terminal *term, char32_t wc, int width, bool insert_mode_disable) { xassert(width > 0); @@ -3918,7 +3918,8 @@ term_print(struct terminal *term, char32_t wc, int width) } print_linewrap(term); - print_insert(term, width); + if (!insert_mode_disable) + print_insert(term, width); int col = grid->cursor.point.col; @@ -3990,7 +3991,7 @@ term_print(struct terminal *term, char32_t wc, int width) static void ascii_printer_generic(struct terminal *term, char32_t wc) { - term_print(term, wc, 1); + term_print(term, wc, 1, false); } static void -- cgit v1.3