Repository navigation
macOS: IME text committed after the marked text is cleared isn't lost (winit#4650) - #676
Merged
echelon merged 2 commits intoOct 10, 2026
Merged
Conversation
… (winit#4650) winit 0.30.13 reports insertText as Ime::Commit only while marked text is left, and after any commit it swallows the next key. Real paths where that loses text: - input methods that end a composition with unmarkText, then insertText (rust-windowing/winit#3925): the committed text was dropped; - Apple Korean 2-Set, for the key typed after a syllable: on 한 then 5 it calls setMarkedText("한"), insertText("한"), setMarkedText(""), insertText("5"), so the 5 (or ;, or any key that ends the syllable) was dropped; - a commit made outside a key press (a candidate clicked with the mouse, dictation): no key follows to reset the state, so the next key (for example Backspace) was swallowed. vendor/winit now commits when a composition was started (pending_commit, set in setMarkedText, cleared by the commit and when IME is disallowed); other insertText calls still reach the app as KeyboardInput. A commit outside keyDown clears the marked text and returns to the ground state. validAttributesForMarkedText lists the underline and marked-clause attributes, which some input methods need before they compose. This is rust-windowing/winit#4650, the 0.30 backport of storytold#4651 (merged on winit master), plus the part of storytold#4748 that fixes storytold#4651's out-of-key-press case (storytold#4748's other parts are not included). One correction: upstream spells the underline attribute "NSUnderlineStyle", but AppKit's NSUnderlineStyleAttributeName is "NSUnderline" (printed on macOS 14), so the AppKit value is used. Checked with the real input methods on macOS 14.7.1 (a scratch winit app fed key events through AppKit): with the patch 한+5 and 한+; commit the 5 and ;, unmarkText-then-insertText commits, and Backspace after a commit outside a key press is delivered; ABC typing, held keys, Japanese (日本, あ), Cangjie (日) and Korean composition give the same events as before. A test fails if a re-vendored winit loses the patch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 10, 2026
# Conflicts: # vendor/README.md
Member
|
Merged, thank you! Committing when a composition was started rather than while marked text remains (winit#4650/#4651) stops input methods that If you haven't already, come join us on Discord: https://discord.gg/artcraft |
This was referenced Oct 10, 2026
krichelj
pushed a commit
to krichelj/pdfcraft
that referenced
this pull request
Oct 11, 2026
… (winit#4650) (storytold#676) winit 0.30.13 reports insertText as Ime::Commit only while marked text is left, and after any commit it swallows the next key. Real paths where that loses text: - input methods that end a composition with unmarkText, then insertText (rust-windowing/winit#3925): the committed text was dropped; - Apple Korean 2-Set, for the key typed after a syllable: on 한 then 5 it calls setMarkedText("한"), insertText("한"), setMarkedText(""), insertText("5"), so the 5 (or ;, or any key that ends the syllable) was dropped; - a commit made outside a key press (a candidate clicked with the mouse, dictation): no key follows to reset the state, so the next key (for example Backspace) was swallowed. vendor/winit now commits when a composition was started (pending_commit, set in setMarkedText, cleared by the commit and when IME is disallowed); other insertText calls still reach the app as KeyboardInput. A commit outside keyDown clears the marked text and returns to the ground state. validAttributesForMarkedText lists the underline and marked-clause attributes, which some input methods need before they compose. This is rust-windowing/winit#4650, the 0.30 backport of storytold#4651 (merged on winit master), plus the part of storytold#4748 that fixes storytold#4651's out-of-key-press case (storytold#4748's other parts are not included). One correction: upstream spells the underline attribute "NSUnderlineStyle", but AppKit's NSUnderlineStyleAttributeName is "NSUnderline" (printed on macOS 14), so the AppKit value is used. Checked with the real input methods on macOS 14.7.1 (a scratch winit app fed key events through AppKit): with the patch 한+5 and 한+; commit the 5 and ;, unmarkText-then-insertText commits, and Backspace after a commit outside a key press is delivered; ABC typing, held keys, Japanese (日本, あ), Cangjie (日) and Korean composition give the same events as before. A test fails if a re-vendored winit loses the patch. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Brandon Thomas <echelon@gmail.com>
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
On macOS, text committed through IME is lost in PdfCraft's text fields when the input method clears its marked text before inserting. This happens with:
5(or;) gives 한 without the 5.unmarkTextbeforeinsertText(incorrectly handle insertText (macOS) rust-windowing/winit#3925).Port of rust-windowing/winit#4650 (reviewed head
565e504d43), the 0.30 backport of winit#4651, which is merged on winit master (5ea1b78d29). It also includes the part of winit#4748 (reviewed head41e556b432) that fixes #4651's out-of-key-press case. The other macOS PRs in this batch build on this one.PdfCraft impact
IME input in every egui text field on macOS: Search, form fields, the JavaScript console, comments, the command palette.
Root cause
vendor/winit/src/platform_impl/macos/view.rs:insertText:reportsIme::Commitonly while marked text is left (hasMarkedText()). Apple Korean callssetMarkedText("한"),insertText("한"),setMarkedText(""),insertText("5"), so the5arrives with no marked text: it is neither committed nor sent as a key, becausekeyDown:treats the key as consumed by IME.Committed. Outside a key press, nokeyDown:follows to clear the marked text and reset the state, so the next key is swallowed.Change
pending_commit: set bysetMarkedText, cleared by a commit and when IME is disallowed.insertTextcommits when a composition was started, rather than when marked text is left. OtherinsertTextcalls (ordinary typing) still reach the app asKeyboardInput, which sign: validate signature dicts and post-signing changes against signed revision (#3998) #4576's broader approach would have broken.in_key_down: a commit outsidekeyDown:clears the marked text and returns to the ground state instead of swallowing the next key (from M7: an added text box or picture dragged onto another page moves there (#4655) #4748).validAttributesForMarkedTextlists the underline and marked-clause attributes; some input methods (落格输入法) don't compose until it is non-empty. Upstream spells the underline key"NSUnderlineStyle", but AppKit'sNSUnderlineStyleAttributeNameis"NSUnderline"(printed on this Mac), so the AppKit value is used. The marked-clause key matches.Not included
How the macOS changes were checked
A scratch winit app (not committed) built against the vendored winit, first unpatched, then with each patch. It picks an input source on its own input context (
NSTextInputContext.selectedKeyboardInputSource), posts key events made fromCGEventCreateKeyboardEventto itself, so AppKit routes them throughkeyDown:andinterpretKeyEvents, and the real input method composes them. It prints winit'sImeandKeyboardInputevents, and AppKit'sNSTextInputClientcalls from winit's own trace spans. Machine: macOS 14.7.1 (23H222), Apple Korean 2-Set, Japanese (Romaji), Cangjie, ABC. Afterwards the input source was set back to ABC.The scenarios are: Korean syllables followed by Space, a digit,
;, Return and Backspace; Space with nothing composed; Japanese 日本 and あ; Cangjie 日; ABC typing; a held key with auto-repeat; IME disallowed and allowed again mid-composition; commits made outside a key press; andunmarkTextfollowed byinsertText. How egui then uses these events was read fromegui-winit0.36.2 (KeyboardInputtext becomesEvent::Text;Ime::Commitinserts into the focusedTextEdit).Before → after (only these events changed; every other scenario gave identical events):
5Commit("한"), the 5 lostCommit("한"),Commit("5");Commit("한"), the ; lostCommit("한"),Commit(";")setMarkedText,unmarkText,insertText("final")Commit("final")KeyboardInput(Backspace)bbcommitted through the stale marked textKeyboardInput("b")Unchanged: ABC typing (
KeyboardInputwith text, noIme::Commit), held keys, Japanese 日本/あ, Cangjie 日, Korean syllables with Space, Return and Backspace.apps/pdfcraft/tests/winit_macos_ime_commit.rsfails if a re-vendored winit loses the patch (each assertion fails onmain).Automated checks
aarch64-apple-darwin,x86_64-pc-windows-msvcandx86_64-unknown-linux-musl(cargo clippy --lib, lints capped to warnings): the warnings are the same as onmainfor all three (the one existingclippy::iter_kv_mapinlinux/x11/event_processor.rs).cargo check --locked -p winitinside the PdfCraft workspace, with PdfCraft's ownCargo.lock, on macOS and on the tree with all nine fixes merged: clean.main(fails);rustfmt --checkandclippy -D warningson it are clean.cargo test --workspaceand workspace clippy (the machine is short of disk space for a full build). CI runs them on Linux and Windows.Risk
Kept as upstream: after a composition cancelled to empty (
setMarkedText("")), the next character inserted by the input method arrives asIme::Commitrather than asKeyboardInput; egui inserts the same text either way. Clearingpending_committhere instead would drop the commit of input methods that clear the preedit right before inserting (the bug fixed here).Revert and removal
This change is independent of the other winit PRs and can be reverted on its own; three PRs in this batch build on it. Drop it, together with the test and README item (6), once PdfCraft uses a winit release that includes rust-windowing/winit#4651/#4650 and the out-of-key-press part of #4748.
Merging alongside the other winit PRs
This is one of nine fixes to
vendor/winitsent together: #672 (Wayland IME after a capability change), #673 (Windows Korean IME caret), #674 (Windows maximized start-up), #675 (X11 input context focus), #676 (macOS IME commit state), #677 (macOS stale composition), and, building on #676, #678 (macOS emoji picker), #679 (macOS Korean double space), #680 (macOS first Korean key). Each adds one numbered item to the single winit row invendor/README.md, so they conflict with each other on that one line, and nowhere else (each test is in its own file). The item numbers (2)–(10) are fixed in advance: to resolve, keep every item in numeric order. All nine were merged locally in one tree (only that line conflicted); the combined vendored winit builds for macOS, Windows and Linux with the same clippy output asmain, and all nine tests pass on it.🤖 Generated with Claude Code