Skip to content

fix(win32): encode KEY_EVENT_RECORD.uChar as UTF-8 for IME input#78

Open
KoalaHao wants to merge 1 commit into
Norbert515:mainfrom
marsup-space:fix/windows-utf8-ime
Open

fix(win32): encode KEY_EVENT_RECORD.uChar as UTF-8 for IME input#78
KoalaHao wants to merge 1 commit into
Norbert515:mainfrom
marsup-space:fix/windows-utf8-ime

Conversation

@KoalaHao
Copy link
Copy Markdown

@KoalaHao KoalaHao commented Jun 5, 2026

KEY_EVENT_RECORD.uChar is a single UTF-16 code unit, but the downstream InputParser decodes as UTF-8 (1/2/3/4-byte sequences dispatched by leading byte). The old code returned String.fromCharCode(char).codeUnits, which for e.g. 你 (U+4F60) produced the int 0x4F60 - not a valid UTF-8 byte - so IME characters (Chinese, Japanese, Korean, anything CJK) never reached the text field.

Now encoded as proper UTF-8 via utf8.encode(), with a _pendingHighSurrogate field to reassemble supplementary-plane characters (e.g. emoji) across two consecutive key events. Orphans are discarded so a half-pair followed by a different key never produces a wrong character.

Verified: 你 (U+4F60) -> 'e4 bd a0', (surrogate pair 0xD83D/0xDE00) -> 'f0 9f 98 80', both round-trip through utf8.decode.

KEY_EVENT_RECORD.uChar is a single UTF-16 code unit, but the
downstream InputParser decodes as UTF-8 (1/2/3/4-byte sequences
dispatched by leading byte). The old code returned
String.fromCharCode(char).codeUnits, which for e.g. 你 (U+4F60)
produced the int 0x4F60 - not a valid UTF-8 byte - so IME
characters (Chinese, Japanese, Korean, anything CJK) never
reached the text field.

Now encoded as proper UTF-8 via utf8.encode(), with a
_pendingHighSurrogate field to reassemble supplementary-plane
characters (e.g. emoji) across two consecutive key events.
Orphans are discarded so a half-pair followed by a different
key never produces a wrong character.

Verified: 你 (U+4F60) -> 'e4 bd a0',  (surrogate pair 0xD83D/0xDE00) -> 'f0 9f 98 80', both round-trip through utf8.decode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant