Skip to content

fix: auto-revert standard ABC switch back to Lexime#207

Merged
send merged 8 commits intomainfrom
fix/escape-abc-revert
Mar 29, 2026
Merged

fix: auto-revert standard ABC switch back to Lexime#207
send merged 8 commits intomainfrom
fix/escape-abc-revert

Conversation

@send
Copy link
Copy Markdown
Owner

@send send commented Mar 28, 2026

Summary

  • ESC や英数キーで IMKit のレース条件により標準 ABC に切り替わる問題への対策
  • InputSourceMonitorcom.apple.keylayout.ABC への切り替えを検知し、自動で Lexime Roman に復帰
  • セキュア入力(パスワードフィールド等)の場合は IsSecureEventInputEnabled() の解除を 500ms ポーリングで検知して復帰
  • commitComposition 時の ESC レース条件はリトライ(5回 × 50ms)で対応

Test plan

  • パスワードフィールド → セキュア入力解除後に Lexime Roman に自動復帰
  • Lexime Japanese / Roman 両方からの復帰を確認
  • ESC での標準 ABC 切り替えが自動復帰されること
  • 英数キーでの標準 ABC 切り替えが自動復帰されること
  • 画面ロック解除後の動作確認

🤖 Generated with Claude Code

send and others added 5 commits March 13, 2026 22:13
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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 LeximeInputController and retry-revert if the system flips to com.apple.keylayout.ABC.
  • Add InputSourceMonitor to observe input source changes and auto-revert from “ABC” back to Lexime (with secure-input polling support).
  • Wire up InputSourceMonitor startup from AppContext.

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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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>
@send send merged commit ddad3c8 into main Mar 29, 2026
10 checks passed
@send send deleted the fix/escape-abc-revert branch March 29, 2026 08:56
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