Skip to content

Conversation

@mylukin
Copy link

@mylukin mylukin commented Jan 17, 2026

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=true but don't go through the composition flow (no compositionstart/compositionend events).

The existing condition (!ev.composed || !this._keyDownSeen) rejects these inputs because:

  • ev.composed is true (crossed shadow DOM boundary)
  • _keyDownSeen is true (keydown fired before input)

Emoji Duplication

On iOS Safari, emoji input causes duplicates because of timing:

  1. compositionend fires → isComposing becomes false
  2. input event fires → xterm.js would accept it (first copy)
  3. setTimeout in 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 composition

Added public getter isSendingComposition to CompositionHelper to expose the _isSendingComposition state.

This correctly handles all cases:

  • ✅ Accepts punctuation input (not composing, not pending)
  • ✅ Rejects input during active composition (CompositionHelper handles it)
  • ✅ Rejects input when CompositionHelper has pending setTimeout
  • ✅ Prevents emoji duplication

Changes

  1. src/browser/input/CompositionHelper.ts: Added isSendingComposition getter
  2. src/browser/Types.ts: Added isSendingComposition to ICompositionHelper interface
  3. src/browser/CoreBrowserTerminal.ts: Updated condition in _inputEvent()

Testing

Tested on iOS Safari with:

  • ✅ Chinese punctuation: ,。!?:;""''
  • ✅ Spaces after Chinese characters
  • ✅ Emoji (no duplication)
  • ✅ Regular English input
  • ✅ CJK character input via IME

Related Issues

Fixes #3070
Fixes #4486

@mylukin mylukin force-pushed the fix/ios-safari-chinese-punctuation-input branch from 447f94b to d7700cd Compare January 17, 2026 07:36
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]>
@mylukin mylukin force-pushed the fix/ios-safari-chinese-punctuation-input branch from d7700cd to c45ddce Compare January 17, 2026 08:19
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]>
@iven
Copy link

iven commented Jan 21, 2026

Will this fix punctuation input in other browsers (like electron)?

@mylukin
Copy link
Author

mylukin commented Jan 21, 2026

Will this fix punctuation input in other browsers (like electron)?

I only tested it on Safari.

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.

Various problems with Chinese IMEs Cannot enter Chinese punctuation in Safari

2 participants