fix: handle insertReplacementText for Korean IME on WKWebView/Safari#5704
Open
minemos wants to merge 1 commit intoxtermjs:masterfrom
Open
fix: handle insertReplacementText for Korean IME on WKWebView/Safari#5704minemos wants to merge 1 commit intoxtermjs:masterfrom
minemos wants to merge 1 commit intoxtermjs:masterfrom
Conversation
WKWebView (used by Tauri, Capacitor, and Safari-based apps) does not fire
compositionstart/compositionupdate/compositionend events for Korean IME input.
Instead, it fires:
- insertText for initial jamo (e.g. 'ㅎ')
- insertReplacementText for composition updates (e.g. 'ㅎ' → '하' → '한')
Since _inputEvent only handles insertText, composed Korean syllables were
silently dropped, causing only raw jamo to reach the terminal.
This patch:
1. Buffers insertReplacementText data and shows composition preview
2. Intercepts Hangul insertText to buffer instead of sending immediately
3. Flushes the composed syllable on next non-IME keydown or new character
4. Adds wkImeComposing flag to CompositionHelper to suppress
_handleAnyTextareaChanges during synthetic WK composition
Tested with Korean (Hangul) IME in Tauri v2 (macOS WKWebView).
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.
Summary
WKWebView (used by Tauri, Capacitor, and Safari-based apps on macOS/iOS) does not fire
compositionstart/compositionupdate/compositionendevents for Korean IME input. Instead, it fires:insertTextwithinputType === 'insertText'for the initial jamo (e.g.ㅎ)insertReplacementTextfor composition updates (e.g.ㅎ→하→한)Since
_inputEvent()only handlesinputType === 'insertText', the composed Korean syllables frominsertReplacementTextwere silently dropped, causing only raw jamo to reach the terminal.Changes
CoreBrowserTerminal.ts(main fix):insertReplacementTextdata instead of dropping it, and show composition previewinsertText(before thecomposed/keyDownSeenguard) to buffer instead of sending immediately — WKWebView may setcomposed=trueon Hangul syllablesCompositionHelper.ts(minimal):wkImeComposingflag to suppress_handleAnyTextareaChanges()during synthetic WK composition (keyCode 229 would otherwise send individual jamo viasetTimeout)Types.ts/TestUtils.test.ts:wkImeComposingtoICompositionHelperinterface and mockHow it works
insertText "ㅎ"ㅎsent to PTYinsertReplacementText "하"하, preview updatedinsertReplacementText "한"한, preview updatedinsertText "..."한flushed to PTY, new buffer startedTesting
Tested with Korean (Hangul) IME in:
This fix is scoped to
insertReplacementTexthandling and Hangul detection, so it should not affect existing composition flows on Chrome/Firefox where standard composition events are fired.Fixes input for Korean IME users on Safari/WKWebView-based terminal applications.