fix(terminal): forward macOS WebKit IME replacement input for Korean/CJK#718
Open
kmsdoit wants to merge 1 commit into
Open
fix(terminal): forward macOS WebKit IME replacement input for Korean/CJK#718kmsdoit wants to merge 1 commit into
kmsdoit wants to merge 1 commit into
Conversation
On macOS (WKWebView) the Korean/CJK IME drives composition through `input` events — `insertText` for a new glyph and `insertReplacementText` as the in-progress syllable is refined (ㅇ → 아 → 안) — and never fires the standard composition* events. xterm forwards `insertText` to the PTY but silently drops `insertReplacementText`, so only the first jamo of each syllable reached the shell: typing "안녕" arrived as "ㅇㄴ". Bridge the gap on the terminal textarea: track the last uncommitted glyph and, on `insertReplacementText`, erase it with DEL and write the refined syllable so the shell mirrors what the IME shows. `insertText` is still handled by xterm; we only record it so the next replacement knows how many code points to erase. This is the remaining half of crynta#147 (the keydown guard from crynta#196 stopped the duplicate raw keys but never restored the dropped replacements). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On macOS (WKWebView) the Korean/CJK IME drives composition through
inputevents —insertTextwhen a new glyph starts andinsertReplacementTextas the in-progress syllable is refined (ㅇ → 아 → 안) — and never fires the standardcomposition*events. xterm forwardsinsertTextto the PTY but silently dropsinsertReplacementText, so only the first jamo of each syllable ever reached the shell.Typing
안녕arrived at the PTY asㅇㄴ. Single jamo worked, but as soon as two combined the syllable broke.Root cause
Captured the real event stream on macOS (Apple Silicon, WKWebView).
isComposingis alwaysfalseand nocompositionstart/update/endever fire — the IME uses onlyinputevents:xterm's
_inputEventonly handlesinputType === "insertText", so every refinement is lost.This is the remaining half of #147 — the keydown guard added in #196 stopped the duplicate raw keydowns, but nothing restored the dropped replacements.
Fix
On the terminal textarea, listen for
inputand bridgeinsertReplacementText: track the last uncommitted glyph (pendingGlyph), and when a replacement arrives, erase the previously sent glyph withDEL(\x7f) and write the refined syllable.insertTextis still handled by xterm; we only record it so the next replacement knows how many code points to erase. The shell now mirrors exactly what the IME shows, and each committed syllable reaches the PTY once.Testing
pnpm tauri devon macOS (Apple Silicon).안녕+ Enter reaches the shell as안녕and runs as expected. Single jamo, multi-syllable words, and Latin input all behave correctly.pnpm exec tsc --noEmit— zero errors.Notes
The replacement is rewritten in place via
DEL, which suits line-editing shells (zsh/bash/readline) — the common case for terminal command entry. The sameinput-event path likely underlies #699 (Cyrillic duplication on Linux/WebKitGTK); I can follow up on that separately.