feat: switch input source during prefix mode (macOS, opt-in)#434
Merged
ogulcancelik merged 2 commits intoJun 3, 2026
Merged
Conversation
8d47c96 to
aae513c
Compare
On macOS, opt-in under [experimental], temporarily switch the host input source to the current ASCII-capable layout while prefix mode is active so prefix commands register even when a CJK IME is composing, then restore the previous input source when prefix mode exits or is cancelled. No-op when the current source is already ASCII-capable, on non-macOS platforms, or when any input source call fails. Pane text input is unaffected. Also pin next_resize_poll in next_loop_deadline_includes_selection_autoscroll_deadline so the selection autoscroll deadline stays the earliest; the default resize poll could otherwise beat it and flake the assertion. refs ogulcancelik#400
aae513c to
4828fe1
Compare
Owner
|
lgtm ty! |
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.
What this does
Implements #400. While prefix mode is active on macOS, switch the system input source to the current ASCII-capable layout, then put back whatever was active once prefix mode ends. Off by default, behind
[experimental] switch_ascii_input_source_in_prefix.The problem: with a Korean (or any non-Latin) IME active, hitting the prefix key works, but the next key often gets composed by the IME instead of read as a command. So prefix commands are unreliable unless you switch to English first.
How it works
The switch hangs off the
Modetransition rather than any new state. After each event is handled, I compare the previous mode against the current one: entering prefix switches to ASCII (only when the flag is on), and leaving prefix — for any reason, including cancel — restores. Keeping it on the mode edge means there's no second flag that can drift out of sync, and every exit path restores through the same point.AppStateonly carries the bool; the actual macOS call lives in the runtime, so state stays pure. The macOS side is all insrc/platform/macos.rsbehind a smallPrefixInputSourcetrait, so the rest of the app never sees the Carbon/CoreFoundation FFI and non-macOS just compiles a no-op. The saved source is held in a struct whoseDropdoes the restore +CFRelease, so it can't leak on an early return.It uses
TISCopyCurrentASCIICapableKeyboardLayoutInputSource, so it picks up whatever ASCII layout you already have — no hard-coded ABC/US. If the current source is already ASCII-capable (compared withCFEqual) or any TIS call fails, it does nothing and input keeps working.Testing
PrefixInputSourceis a trait so the transitions are covered with a fake — enter/leave, flag off, and the already-ASCII / failed-switch case where the later restore has to stay harmless. There's also a dispatch-level test that Esc out of prefix restores, since the exit is decided belowhandle_key.just cipasses; I also ran the widerjust check(clippy-D warnings+ the python unittests). Verified by hand on macOS with a Korean IME: prefix commands land mid-composition, and my IME comes back when prefix mode ends.Docs
New
[experimental]option, so I updateddocs/next/website/src/content/docs/configuration.mdxfor the next release. Leftdocs/next/CHANGELOG.mdalone (maintainers handle that at release), and didn't touch root README/CHANGELOG or the released website docs.