fix: auto-revert standard ABC switch back to Lexime#207
Conversation
Due to a race condition in IMKit, ESC during composing can sometimes cause macOS to switch the input source to com.apple.keylayout.ABC even though we return consumed=true. After ESC-triggered commitComposition, check the input source after 50ms and revert to Lexime Japanese if standard ABC was selected. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The single 50ms delayed check was insufficient to catch the race condition where macOS switches to standard ABC after ESC during composing. Retry up to 5 times (250ms total) to reliably detect and revert the switch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Monitors input source changes via DistributedNotificationCenter and sends a macnotifier notification when the system switches to standard ABC unexpectedly. Tapping the notification switches back to Lexime. Includes lexime-select-input helper binary for notification actions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When ABC switch is caused by secure input (e.g. password fields), poll IsSecureEventInputEnabled() at 500ms intervals and automatically switch back to the previous Lexime mode (Japanese or Roman) when secure input is released. Also tracks the last active Lexime source ID so both notification actions and auto-revert restore the correct mode. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove macnotifier notification and lexime-select-input helper in favor of automatic revert to Lexime Roman. All standard ABC switches (both secure input and IMKit race conditions) now auto-revert without user intervention. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Addresses a macOS IMKit race where pressing ESC / 英数 can unexpectedly switch the active input source to the system “ABC” layout, by detecting that switch and programmatically switching back to Lexime.
Changes:
- Track ESC-triggered commits in
LeximeInputControllerand retry-revert if the system flips tocom.apple.keylayout.ABC. - Add
InputSourceMonitorto observe input source changes and auto-revert from “ABC” back to Lexime (with secure-input polling support). - Wire up
InputSourceMonitorstartup fromAppContext.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Sources/LeximeInputController.swift | Adds ESC commit tracking and a retry loop to revert if the input source flips to system ABC. |
| Sources/InputSourceMonitor.swift | New distributed-notification observer that detects ABC selection and auto-switches back to Lexime, including secure-input polling. |
| Sources/AppContext.swift | Instantiates and starts the new input source monitor at app startup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot review: - Remove unused leximeJapaneseID constant - Update class doc comment to reflect auto-revert behavior (no longer uses macnotifier notifications) - Add comment explaining runtime ID prefix difference from Info.plist Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add LeximeInputSourceID enum that derives runtime input source IDs from Bundle.main.bundleIdentifier, eliminating hard-coded "Lexime.Lexime.*" strings. Used by both InputSourceMonitor and LeximeInputController for TISCreateInputSourceList lookups. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Update doc comments to accurately describe: - japaneseModeID/romanModeID: IMKit mode IDs from Info.plist, used by setValue(_:forTag:client:) - LeximeInputSourceID: runtime IDs with bundle ID prefix, used by TIS API (TISCreateInputSourceList) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
InputSourceMonitorでcom.apple.keylayout.ABCへの切り替えを検知し、自動で Lexime Roman に復帰IsSecureEventInputEnabled()の解除を 500ms ポーリングで検知して復帰commitComposition時の ESC レース条件はリトライ(5回 × 50ms)で対応Test plan
🤖 Generated with Claude Code