fix: iOS Safari Chinese punctuation input not working#5614
Open
mylukin wants to merge 2 commits intoxtermjs:masterfrom
Open
fix: iOS Safari Chinese punctuation input not working#5614mylukin wants to merge 2 commits intoxtermjs:masterfrom
mylukin wants to merge 2 commits intoxtermjs:masterfrom
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 <[email protected]>
d7700cd to
c45ddce
Compare
mylukin
added a commit
to mylukin/webtmux
that referenced
this pull request
Jan 17, 2026
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 <[email protected]>
|
Will this fix punctuation input in other browsers (like electron)? |
Author
I only tested it on Safari. |
Member
|
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? |
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
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