Repository navigation
Fix macOS Chinese IME full-width punctuation and window-switch input - #6417
Conversation
Two macOS IME regressions in the terminal: - Full-width punctuation (,。?!) was sent as half-width ASCII. With kitty keyboard on, xterm encodes+sends the ASCII symbol on keydown and preventDefaults it, dropping the IME's committed glyph from the input event. Bypass those punctuation keydowns/keypress/keyup so the native input pipeline runs, then forward the committed glyph to the PTY. - After switching windows, the IME stayed stuck in ASCII with no way back to CJK. macOS+Chromium leaves a stale NSTextInputContext on the still focused helper textarea after reactivation (electron#32307/stablyai#34952). Force a blur -> next-frame refocus on window focus to rebuild it. Both paths are macOS-scoped where relevant and covered by unit tests.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe PR updates terminal focus resynchronization to use a macOS-specific blur-and-refocus path with next-frame scheduling, adds Mac CJK input-source tracking, and adds an IME punctuation forwarder for terminal panes. It also wires the forwarder into pane lifecycle and key handling, and expands tests for focus, input-source tracking, and punctuation forwarding behavior. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 1ea663f1-6038-4d4e-91fd-714fc5e17c01
📒 Files selected for processing (5)
src/renderer/src/components/terminal-pane/regular-terminal-focus-ownership.test.tssrc/renderer/src/components/terminal-pane/regular-terminal-focus-ownership.tssrc/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
AmethystLiang
left a comment
There was a problem hiding this comment.
Thanks, this is a good fix. I added a small maintainer follow-up before landing:
- Gate the punctuation bypass to macOS CJK input sources so ordinary punctuation on US/European layouts keeps xterm/kitty behavior.
- Stop the handled input event after forwarding so it cannot be processed a second time by later xterm input listeners.
- Add regression coverage for Chinese/Japanese punctuation, CJK input-source detection, disabled/source-change behavior, and composition takeover.
Validated with typecheck, lint, targeted Vitest, and Electron on macOS with a Pinyin input source.
…keyboard protocol (#6513) (#6575) * fix(terminal): forward synthesized/dictated text dropped under kitty keyboard protocol With xterm's kitty keyboard protocol active, xterm encodes a printable key on keydown and preventDefaults it, which cancels Chromium's native insertText on the helper textarea. The IME punctuation forwarder added in #6417 was gated to CJK input sources (isEnabled), so on a non-CJK (e.g. U.S. Latin) input source it never armed and any synthesized text — dictation, text expanders, accessibility / CGEvent injection — was silently dropped before reaching the PTY. Part A: drop the CJK-only gate so the forwarder arms on macOS regardless of input source (the drop affects every locale, not just CJK punctuation). Part B: forward a standalone non-composing insertText that no key event produced. Injected prose/words never satisfy the punctuation-keydown claim path, so recover them from the helper-textarea input event, guarded against double-send (key-activity attribution, unresolved claimed press), against composition (insertCompositionText + composition-commit), and via stopImmediatePropagation so xterm's own _inputEvent cannot also forward. Fixes #6513 Co-authored-by: Orca <[email protected]> * fix: broaden terminal injected text forwarding --------- Co-authored-by: Orca <[email protected]>
…tablyai#6417) * Fix macOS Chinese IME full-width punctuation and window-switch input Two macOS IME regressions in the terminal: - Full-width punctuation (,。?!) was sent as half-width ASCII. With kitty keyboard on, xterm encodes+sends the ASCII symbol on keydown and preventDefaults it, dropping the IME's committed glyph from the input event. Bypass those punctuation keydowns/keypress/keyup so the native input pipeline runs, then forward the committed glyph to the PTY. - After switching windows, the IME stayed stuck in ASCII with no way back to CJK. macOS+Chromium leaves a stale NSTextInputContext on the still focused helper textarea after reactivation (electron#32307/stablyai#34952). Force a blur -> next-frame refocus on window focus to rebuild it. Both paths are macOS-scoped where relevant and covered by unit tests. * Tighten macOS IME punctuation handling --------- Co-authored-by: Jinjing <[email protected]>
…keyboard protocol (stablyai#6513) (stablyai#6575) * fix(terminal): forward synthesized/dictated text dropped under kitty keyboard protocol With xterm's kitty keyboard protocol active, xterm encodes a printable key on keydown and preventDefaults it, which cancels Chromium's native insertText on the helper textarea. The IME punctuation forwarder added in stablyai#6417 was gated to CJK input sources (isEnabled), so on a non-CJK (e.g. U.S. Latin) input source it never armed and any synthesized text — dictation, text expanders, accessibility / CGEvent injection — was silently dropped before reaching the PTY. Part A: drop the CJK-only gate so the forwarder arms on macOS regardless of input source (the drop affects every locale, not just CJK punctuation). Part B: forward a standalone non-composing insertText that no key event produced. Injected prose/words never satisfy the punctuation-keydown claim path, so recover them from the helper-textarea input event, guarded against double-send (key-activity attribution, unresolved claimed press), against composition (insertCompositionText + composition-commit), and via stopImmediatePropagation so xterm's own _inputEvent cannot also forward. Fixes stablyai#6513 Co-authored-by: Orca <[email protected]> * fix: broaden terminal injected text forwarding --------- Co-authored-by: Orca <[email protected]>
Two macOS IME regressions in the terminal:
Full-width punctuation (,。?!) was sent as half-width ASCII. With kitty keyboard on, xterm encodes+sends the ASCII symbol on keydown and preventDefaults it, dropping the IME's committed glyph from the input event. Bypass those punctuation keydowns/keypress/keyup so the native input pipeline runs, then forward the committed glyph to the PTY.
After switching windows, the IME stayed stuck in ASCII with no way back to CJK. macOS+Chromium leaves a stale NSTextInputContext on the still focused helper textarea after reactivation (electron#32307/fix(editor): keep notebook cell undo across cell and tab switches #34952). Force a blur -> next-frame refocus on window focus to rebuild it.
Both paths are macOS-scoped where relevant and covered by unit tests.
Summary
Describe the user-visible change.
Screenshots
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildAI Review Report
AI review focused on the terminal IME punctuation forwarding and macOS focus reactivation changes. It checked event ordering around keydown →
keypress → input → keyup, xterm kitty keyboard release handling, lifecycle cleanup, and whether the macOS IME context refresh could steal focus.
The review flagged one issue: the IME punctuation forwarder could claim keypress / keyup even when it had not claimed the matching keydown, which
could swallow an unmatched kitty release event. I fixed this by tracking whether the forwarder owned the current key press, and added regression
coverage for both unmatched keypress/keyup and post-input keyup handling.
Cross-platform compatibility was explicitly reviewed for macOS, Linux, and Windows:
• Shortcuts: modifier chords are excluded from IME punctuation forwarding, preserving Ctrl/Cmd/Alt shortcuts.
• Labels: no UI shortcut labels were changed.
• Paths: no file path handling was touched.
• Shell behavior: forwarded text still goes through terminal input; no shell command construction was added.
• Electron/platform differences: macOS-only blur/refocus remains gated to Mac user agents; non-macOS skips that focus cycle.
Verified with Node 24.18.0:
terminal-ime-punctuation-forwarder.test.ts passed, 18/18 tests.
Security Audit
Reviewed input handling, command execution, path handling, auth/secrets, dependencies, and IPC impact for the touched code.
No new command execution, filesystem path handling, authentication, secrets, dependencies, or IPC surface was introduced. The main security-relevant
area is terminal input handling: the change only forwards committed InputEvent.insertText data after a locally claimed punctuation key event, and
ignores modifier chords, composition-owned events, and unrelated input. This keeps shortcut handling and terminal control sequences from being
broadened unexpectedly.
No follow-up security work is required beyond the existing lint issue: local oxlint could not run because the native optional binding
@oxlint/binding-darwin-arm64 is missing from the install.
Notes
Call out any platform-specific behavior, risks, or follow-up work.