Skip to content

Fix macOS Chinese IME full-width punctuation and window-switch input - #6417

Merged
AmethystLiang merged 2 commits into
stablyai:mainfrom
lvfen:fix-fix_input_ch
Jun 26, 2026
Merged

AmethystLiang merged 2 commits into
stablyai:mainfrom
lvfen:fix-fix_input_ch

Conversation

@lvfen

@lvfen lvfen commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

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

  • before:
image
  • after:
image

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

AI 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.

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.
@coderabbitai

coderabbitai Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main macOS IME punctuation and window-focus fix.
Description check ✅ Passed The description includes the required summary, screenshots, testing, AI review, security audit, and notes sections with relevant details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1ea663f1-6038-4d4e-91fd-714fc5e17c01

📥 Commits

Reviewing files that changed from the base of the PR and between cdb45d1 and e5eca30.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/regular-terminal-focus-ownership.test.ts
  • src/renderer/src/components/terminal-pane/regular-terminal-focus-ownership.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts

@AmethystLiang AmethystLiang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@AmethystLiang
AmethystLiang merged commit 3cd7193 into stablyai:main Jun 26, 2026
nwparker added a commit that referenced this pull request Jun 28, 2026
…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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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.

2 participants