fix: iOS Safari Chinese punctuation input not working#5614
Conversation
447f94b to
d7700cd
Compare
Fix input handling for Chinese punctuation (,。!?) and emoji on iOS Safari. The issue occurs because: 1. iOS Safari fires keydown (setting _keyDownSeen=true) 2. Then fires input event with ev.composed=true 3. But NO composition events are triggered for punctuation The old condition `(!ev.composed || !this._keyDownSeen)` would reject these inputs because both conditions are true. For emoji, there's a timing issue: 1. compositionend fires → isComposing becomes false 2. input event fires → old fix would accept (duplicate!) 3. setTimeout in CompositionHelper fires → sends emoji (first copy) The fix: 1. Change condition to check `!compositionHelper.isComposing` 2. Also check `!compositionHelper.isSendingComposition` to catch the window between compositionend and setTimeout callback 3. Add public getter for isSendingComposition in CompositionHelper This correctly: - Accepts punctuation input (not composing, not pending) - Rejects input during active composition - Rejects input when CompositionHelper has pending setTimeout - Prevents emoji duplication Fixes xtermjs#3070, xtermjs#4486 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
d7700cd to
c45ddce
Compare
Add workaround patch for xterm.js iOS Safari input issues. Fixed: - Chinese punctuation (,。!?) now works on iOS Safari - Spaces after Chinese characters now work - Chinese character input continues to work Known issue: - Emoji input on iOS Safari still has problems (see docs/ios-safari-input-issues.md) Technical details: - xterm.js drops input when ev.composed=true && _keyDownSeen=true - Our patch listens for input events and recovers dropped characters - Uses composition event timing to prevent duplication Related PR: xtermjs/xterm.js#5614 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Will this fix punctuation input in other browsers (like electron)? |
I only tested it on Safari. |
|
I don't have an iOS device and punctuation seems to work fine for me on latest on macOS/Safari. I recently discovered some quirks around composition events in #5704 on Safari but those affected desktop as well. Do you know of any way to reproduce this on desktop? |
Perhaps I understand why you can't reproduce the problem. Some Chinese input methods used in China (such as Sogou) don't include MacOS's built-in input method doesn't exhibit this behavior. Therefore, you can't reproduce the problem. Considering that |
Summary
Fix Chinese punctuation input (,。!?) and emoji not working correctly on iOS Safari.
Problem
Chinese Punctuation
On iOS Safari, Chinese punctuation and spaces are dropped when using IME input. The input events have
ev.composed=truebut don't go through the composition flow (nocompositionstart/compositionendevents).The existing condition
(!ev.composed || !this._keyDownSeen)rejects these inputs because:ev.composedistrue(crossed shadow DOM boundary)_keyDownSeenistrue(keydown fired before input)Emoji Duplication
On iOS Safari, emoji input causes duplicates because of timing:
compositionendfires →isComposingbecomesfalseinputevent fires → xterm.js would accept it (first copy)setTimeoutin CompositionHelper fires → sends emoji (second copy)Solution
Replace the condition with two checks:
!compositionHelper.isComposing- not actively composing!compositionHelper.isSendingComposition- no pending setTimeout to send compositionAdded public getter
isSendingCompositionto CompositionHelper to expose the_isSendingCompositionstate.This correctly handles all cases:
Changes
src/browser/input/CompositionHelper.ts: AddedisSendingCompositiongettersrc/browser/Types.ts: AddedisSendingCompositiontoICompositionHelperinterfacesrc/browser/CoreBrowserTerminal.ts: Updated condition in_inputEvent()Testing
Tested on iOS Safari with:
Related Issues
Fixes #3070
Fixes #4486