Conversation
On macOS, an IME's direct-commit of a shifted character (e.g. the full-width ? from Shift+/ with Chinese Pinyin) can deliver beforeinput/input before the character's own keydown, in Safari and WKWebView alike. Because the held modifier's keydown had armed the _keyDownSeen gate, _inputEvent wrongly dedupes and drops the first insertText; the character's keyup then resets the flag, so only the first press is lost and the user has to type the key twice. A modifier-only keydown never produces text, so it must not arm the gate. Reuse wasModifierKeyOnlyEvent (the same helper _keyUp uses) so the flag stays disarmed while Shift/Ctrl/Alt/Meta is held. Co-Authored-By: Claude Code <noreply@anthropic.com>
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.
Problem
On macOS, typing an IME's shifted punctuation with a direct commit — e.g. Shift+/ for the full-width
?with Chinese Pinyin — silently drops the first press; the user has to type the key twice. Reproduced in Safari and in WKWebView (Tauri), reported as the held-modifier variant in #5887 (Zhuyin, Tauri 2 + WKWebView), #6144 (Pinyin, orderbeforeinput → input → keydown) and #5374 (JP layout, Shift+3 / Shift+2).Real-device trace captured on macOS 26 (WKWebView, Tauri, Apple Pinyin), from capture-phase listeners on the helper textarea —
_keyDownSeenread before xterm's own handling:So only the first press is lost: the held modifier's keydown arms the gate, the character's keyup disarms it.
Fix
_keyDownSeen's only consumer is the_inputEventdedupe guard. A modifier-only keydown never produces text, so arming the gate for it can only produce false positives — aninsertTextarriving while a modifier is held can only be an IME direct commit that no keydown delivered yet. The fix reuseswasModifierKeyOnlyEvent, the same helper_keyUpalready uses:The regular path is unchanged: a character keydown still arms the gate so its own
insertTextstays deduped (covered by a test).Scope / not claimed to fix
_handleAnyTextareaChangesduplicates or drops characters on key rollover when IME reports keyCode=229 (companion defect to #5887) #6045 analyzes how the gate and the deferred textarea diff interact) needs a coordinated change to both the gate and_handleAnyTextareaChanges; Deferred textarea diff in_handleAnyTextareaChangesduplicates or drops characters on key rollover when IME reports keyCode=229 (companion defect to #5887) #6045 warns that touching the gate alone converts drops into duplications there. This PR deliberately does not touch that.wasModifierKeyOnlyEventdoes not include CapsLock (keyCode 20), so the CapsLock variant mentioned on Cannot type Shifted characters (e.g. #, ") or overlapping keys in Safari on macOS #5374 is not covered; extending the helper would also change_keyUp's focus semantics, so I left that to maintainer judgment.🤖 Generated with Claude Code