]> Sergey Matveev's repositories - st.git/commitdiff
Fix for wide character being incorrectly cleared on MODE_INSERT
authorShi Tian <shitian@cock.li>
Sun, 25 Jun 2023 05:38:33 +0000 (05:38 +0000)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Sun, 25 Jun 2023 09:59:06 +0000 (11:59 +0200)
Under insert mode, when inserting a normal character in front of
a wide character, the affected region is shifted to the right by
one cell. However, the empty cell is reset as if being a part of a
wide character, causing the following cell being mishandled as a
dummy cell.
To reproduce the bug:
printf '\033[4h' # set MODE_INSERT
printf 妳好
printf '\033[4D'
printf 'x'
printf '\033[4l\n'

st.c

diff --git a/st.c b/st.c
index 134e7242e9b18d33dd82df401cbd266d9b9f30fd..623376e1b172781f66dd21ef220e165a8146eaad 100644 (file)
--- a/st.c
+++ b/st.c
@@ -2471,8 +2471,10 @@ check_control_code:
                gp = &term.line[term.c.y][term.c.x];
        }
 
-       if (IS_SET(MODE_INSERT) && term.c.x+width < term.col)
+       if (IS_SET(MODE_INSERT) && term.c.x+width < term.col) {
                memmove(gp+width, gp, (term.col - term.c.x - width) * sizeof(Glyph));
+               gp->mode &= ~ATTR_WIDE;
+       }
 
        if (term.c.x+width > term.col) {
                tnewline(1);