]> Sergey Matveev's repositories - st.git/commitdiff
Fix overtyping wide characters.
authorjamin <acdimalev@gmail.com>
Wed, 29 Dec 2021 17:07:17 +0000 (09:07 -0800)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Thu, 30 Dec 2021 17:37:17 +0000 (18:37 +0100)
Overtyping the first half of a wide character with the
second half of a wide character results in display garbage.
This is because the trailing dummy is not cleaned up.

i.e.  ATTR_WIDE, ATTR_WDUMMY, ATTR_WDUMMY

Here is a short script for demonstrating the behavior:

#!/bin/sh
alias printf=/usr/bin/printf
printf こんにちは!; sleep 2
printf '\x1b[5D'; sleep 2
printf へ; sleep 2
printf ' '; sleep 2
echo

st.c

diff --git a/st.c b/st.c
index de2dd0ec88c489ac332b223fdef10923198c62d0..51049ba22b86cb7f13d99b1c880504c0362ba320 100644 (file)
--- a/st.c
+++ b/st.c
@@ -2507,6 +2507,10 @@ check_control_code:
        if (width == 2) {
                gp->mode |= ATTR_WIDE;
                if (term.c.x+1 < term.col) {
+                       if (gp[1].mode == ATTR_WIDE && term.c.x+2 < term.col) {
+                               gp[2].u = ' ';
+                               gp[2].mode &= ~ATTR_WDUMMY;
+                       }
                        gp[1].u = '\0';
                        gp[1].mode = ATTR_WDUMMY;
                }