fix(macos): NSTextInputClient IME commit flow ( on master branch) - #4651
Open
gzm55 wants to merge 1 commit into
Open
fix(macos): NSTextInputClient IME commit flow ( on master branch)#4651gzm55 wants to merge 1 commit into
gzm55 wants to merge 1 commit into
Conversation
Three fixes for NSTextInputClient protocol implementation: 1. validAttributesForMarkedText now returns standard attributes (NSUnderlineStyle, NSMarkedClauseSegment) instead of an empty array. Some IMEs (e.g. LogInputMac3) require non-empty return to enter composition mode. 2. insertText:replacementRange: no longer gates commit on hasMarkedText(). Some IMEs call unmarkText before insertText, which clears the marked text and caused all commits to be silently discarded. 3. Added pending_commit flag to distinguish genuine composition commits from regular typing during IME mode (spaces, English chars), which should go through keyboard input.
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.
port #4650 to master.
Fixes #3925 — macOS
insertText:replacementRange:incorrectly discards committed text when the IME callsunmarkTextbeforeinsertText, and when the IME requires a non-emptyvalidAttributesForMarkedTextto enter composition.Three targeted fixes in
src/platform_impl/macos/view.rs:1.
validAttributesForMarkedTextreturns standard attributesSome IMEs (e.g. 落格输入法 / LogInputMac3) require a non-empty return to enter composition mode. Apple's docs specify at minimum
NSUnderlineStyleAttributeNameandNSMarkedClauseSegmentAttributeName.2.
insertText:decouples marked-text clearing from commitThe old code required
hasMarkedText() == trueto commit, but some IMEs callunmarkTextbeforeinsertText(clearing the marked text), which silently discarded all committed text. Apple's documentation forinsertText:replacementRange:states that the provided string should be inserted regardless of whether there is marked text.Commit is now gated on
pending_commit && ime_enabledinstead ofhas_marked && ime_enabled.3.
pending_commitflag distinguishes composition commits from regular typingSimply removing the
hasMarkedTextcheck (as attempted in #4576) causes allinsertTextcalls — including spaces and English characters during IME mode — to go throughIme::Commit. This losesKeyboardInputevents and causes downstream visual artifacts (e.g. bracketed paste highlighting in Alacritty).The
pending_commitflag is set totrueinsetMarkedText:(only during actual composition) and checked + cleared ininsertText:. This ensures:pending_committrueIme::Commit✅falseKeyboardInput✅falseKeyboardInput(see notes)Related PRs
hasMarkedTextbut doesn't addpending_commit, causing all typing during IME to go throughIme::Commit— this breaks Russian layouts and creates paste artifacts.marked_textafter commit).Why
pending_commitis necessarykchibisov noted that removing the condition would lose
KeyboardInput, and checking for ASCII is wrong since Russian layout shouldn't go through IME. Thepending_commitflag ensures that only keystrokes that actually initiated a composition session result inIme::Commit— everything else preserves the existingKeyboardInputpath.This matches how Kitty's IME handling works: query IME first, then decide whether the key was consumed by composition or should be forwarded as a key event.
Tested