fix: handle insertReplacementText for Korean IME on WKWebView/Safari#5704
Open
minemos wants to merge 4 commits into
Open
fix: handle insertReplacementText for Korean IME on WKWebView/Safari#5704minemos wants to merge 4 commits into
minemos wants to merge 4 commits into
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).
|
Thanks. This patch works fine for tauri 2.0. macos 26.3(25D125), safari, rust and tauri env. hope to merge this on later version xterm.js 6.x.x. |
Tyriar
requested changes
Mar 10, 2026
Comment on lines
+123
to
+128
| /** | ||
| * WKWebView IME workaround: holds the latest composed text from | ||
| * insertReplacementText events, flushed on next insertText or non-IME keydown. | ||
| */ | ||
| private _wkImeComposing: boolean = false; | ||
| private _wkImePending: string = ''; |
Member
There was a problem hiding this comment.
I looked at how the events work Safari and it's unfortunate. How about instead of hardcoding this stuff into CoreBrowserTerminal, have a WkHangulCompositionEventEmulator that maps insertText/insertReplacementText events into compositionstart/update/end events? This class could then also be created only when it looks like webkit.
Member
Member
bang9
added a commit
to bang9/ai-tools
that referenced
this pull request
Mar 17, 2026
Apply changes from xtermjs/xterm.js#5704 as a pnpm patch. Adds WKWebView IME workaround that handles insertReplacementText events for Korean (Hangul) composition input, which WKWebView/Safari fires instead of standard composition events. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
dong-park
added a commit
to dong-park/pharos
that referenced
this pull request
Apr 16, 2026
WKWebView는 한글 IME에 compositionstart/end 이벤트를 발화하지 않아 xterm.js가 자모를 개별 전송하는 문제를 wk-hangul-ime 모듈로 해결. - wk-hangul-ime 모듈 추가 (github:thedalbee/wk-hangul-ime) - terminalManager.ts에 IME 핸들러 연결 - PTY spawn 시 LANG/LC_ALL UTF-8 로케일 설정 추가 Ref: xtermjs/xterm.js#5704 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mvhenten
added a commit
to mvhenten/mobux
that referenced
this pull request
Apr 28, 2026
Monkey-patch xterm.js 5.3.0 to fix three bugs on mobile: 1. Composition-based autocomplete: keyboards select all textarea content via compositionstart then replace it. xterm.js _finalizeComposition computes wrong substring offset, sending garbled partial text. Fix: detect selection at compositionstart, send proper diff at compositionend, block xterm.js stale send for 50ms. 2. Broken diff in _handleAnyTextareaChanges: uses String.replace which fails when autocorrect changes characters (not just appends). Fix: proper character-level prefix diff. 3. Backspace flood on Enter: _handleAnyTextareaChanges timer fires after xterm.js clears textarea, sending massive backspace sequence. Fix: skip when newValue is empty. Includes diagnostic logging to /api/debug endpoint (POST to debug-input.log) for ongoing mobile input debugging. Refs: xtermjs/xterm.js#5704, xtermjs/xterm.js#2403 Closes: #9
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.