Skip to content

fix: handle insertReplacementText for Korean IME on WKWebView/Safari#5704

Open
minemos wants to merge 1 commit intoxtermjs:masterfrom
minemos:fix/wkwebview-korean-ime
Open

fix: handle insertReplacementText for Korean IME on WKWebView/Safari#5704
minemos wants to merge 1 commit intoxtermjs:masterfrom
minemos:fix/wkwebview-korean-ime

Conversation

@minemos
Copy link

@minemos minemos commented Feb 16, 2026

Summary

WKWebView (used by Tauri, Capacitor, and Safari-based apps on macOS/iOS) does not fire compositionstart/compositionupdate/compositionend events for Korean IME input. Instead, it fires:

  • insertText with inputType === 'insertText' for the initial jamo (e.g. )
  • insertReplacementText for composition updates (e.g. )

Since _inputEvent() only handles inputType === 'insertText', the composed Korean syllables from insertReplacementText were silently dropped, causing only raw jamo to reach the terminal.

Changes

CoreBrowserTerminal.ts (main fix):

  • Buffer insertReplacementText data instead of dropping it, and show composition preview
  • Intercept Hangul insertText (before the composed/keyDownSeen guard) to buffer instead of sending immediately — WKWebView may set composed=true on Hangul syllables
  • Flush the buffered composed syllable on next non-IME keydown or new character
  • Show composition preview on first jamo; defer preview when flushing to avoid stale cursor position

CompositionHelper.ts (minimal):

  • Add wkImeComposing flag to suppress _handleAnyTextareaChanges() during synthetic WK composition (keyCode 229 would otherwise send individual jamo via setTimeout)

Types.ts / TestUtils.test.ts:

  • Add wkImeComposing to ICompositionHelper interface and mock

How it works

User types WKWebView event Before this fix After this fix
insertText "ㅎ" sent to PTY Buffered, preview shown
insertReplacementText "하" Dropped Buffer updated to , preview updated
insertReplacementText "한" Dropped Buffer updated to , preview updated
(next char) insertText "..." flushed to PTY, new buffer started

Testing

Tested with Korean (Hangul) IME in:

  • Tauri v2 on macOS (WKWebView)

This fix is scoped to insertReplacementText handling 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.

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).
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