Repository navigation
fix(search/macos): don't consume Return during IME composition on macOS - #2690
Merged
Merged
Conversation
The search bar's OnCharEvent unconditionally calls Submit() on Enter, which "eats" the Enter that a user pressed to commit an IME candidate (e.g. a Chinese / Japanese / Korean character selection). The result is that the highlighted match is expanded the moment the user tries to finalize their IME input, instead of the IME committing the candidate into the search box. Add a macOS-only helper (search_mac.mm) that asks the key window's first responder whether it currently has marked text — that is the canonical way to detect an in-progress IME composition on Cocoa (NSTextInputClient.hasMarkedText). In OnCharEvent, if a composition is in progress when Enter arrives, skip the event so the IME can consume it, instead of submitting the search. Behavior on Windows / Linux is unchanged; this path is guarded by __WXOSX__ since the underlying detection is Cocoa-specific. Equivalent detection on Windows (IMM API: ImmGetCompositionString) and on Linux (IBus / fcitx via the IM module) can be added in follow-up commits.
AucaCoyan
approved these changes
Jul 19, 2026
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.
Summary
Returnwhile an IME composition is in progress on macOS.Returnto land whatever the IME is currently holding — typically the raw Latin letters they just typed (e.g.lee,ka,gye) — into the search field, instead of triggering whichever match happens to be highlighted.Demo
Both videos captured on macOS Tahoe 26 (Apple Silicon, Apple Pinyin IME, ~130 user-defined snippets).
Before (espanso 2.3.0, brew cask)
Typing the pinyin
Poinunder a CJK IME and pressingReturnto commitPointto the search field — instead, espanso firesSubmit()immediately, picking whichever match is currently highlighted (the first item01trie, since the search field is still empty because the IME never got to commit). The wrong snippet then expands into vim:After (this PR, built from
znzryb/espanso fix/search-bar-ime-enter-cjk)Same exact keystrokes — first
Returnnow lets the IME commitPointinto the search field, the matches re-filter, and the secondReturnexpands the intendedPointclass snippet into vim:Why this matters
Today
SearchFrame::OnCharEventunconditionally callsSubmit()onWXK_RETURN/WXK_NUMPAD_ENTER. To understand why that's a hard blocker under a CJK IME, it helps to spell out how those IMEs work:When a CJK IME is active, the keys you press do not go straight into the focused text field. They first land in the IME's own preedit buffer and are shown as underlined "marked text" inside the field. The user then has to actively tell the IME how to commit that buffer:
Space→ convert to Chinese / kana candidates and pick the first one.1/2/3/ … → pick a numbered candidate.Return→ commit the raw Latin letters as-is (e.g.leelands as the three ASCII charactersl,e,e, not as李/累/etc.). This is the only path that gets any text into the field if the user doesn't want IME conversion.So
Returnhere isn't an "optional submit shortcut" — it's the only way to land even ASCII letters into the search bar while a CJK IME layout is active. Espanso swallowingReturntherefore has two failure modes stacked on top of each other:Returnnever reaches the IME, no text at all — Chinese, kana, or raw Latin — can be typed into the search field while a CJK IME layout is the active one.This makes the search bar effectively unusable for CJK users without first toggling the IME off to a plain US layout.
Approach
espanso-modulo/src/sys/search/search_mac.mmexposesIsImeComposingInKeyWindow(), which asks the key window's first responder whether it has marked text viaNSTextInputClient.hasMarkedText. NSTextField uses a shared field editor (an NSTextView), so the helper checks the responder directly, then falls back tocurrentEditor, then to theNSTextInputClientprotocol.Returnbranch inOnCharEventconsults this on macOS before callingSubmit(). If a composition is in progress, the event is passed through (event.Skip()) so the IME can finalize whatever it's holding (raw Latin letters or a converted candidate); otherwise the existing submit behavior is preserved.build.rsis updated to compile the new.mmalongside the existingsrc/sys/common/mac.mm.#ifdef __WXOSX__). The same class of bug exists there but needs different APIs (IMM on Windows, IBus/preedit on Linux) — left as platform-specific follow-up.This is the search-bar-UI counterpart of #1968, which is the same class of problem in the trigger engine.
Testing
Built and tested locally on macOS Tahoe 26 (Darwin 25.2.0), Apple Silicon:
ALT+SPACEwhile macOS Pinyin IME is active → typelee→Returnlandslee(Latin literal) in the search field instead of triggering the highlight → matches re-filter on the new query → secondReturn(no marked text) submits the highlighted match into the target app, as before.Returnstill immediately submits the highlighted match. No behavior change vs.dev.~/Library/Application Support/espanso/with ~130 user-defined matches; expansion into the target app works correctly after a CJK-IME-mediated search session.Follow-ups (intentionally out of scope)
search/and reused on the trigger detection side.Test plan
Returnlands Latin literal in field, doesn't fire highlightReturnstill submits highlight (no regression)