[macOS] IME preedit lost on focus change - #21601
Conversation
2026-06-17.3.42.19.mov |
|
|
@cla-avalonia agree |
There was a problem hiding this comment.
Pull request overview
Fixes macOS Korean IME composition (preedit) loss/misplacement when focus changes by ensuring the native NSTextInputContext gets a chance to commit an active composition on mouse-down, and by explicitly resetting native/managed preedit state on input-client changes.
Changes:
- Forward mouse button-down events to
NSTextInputContextwhen there is active marked text so the IME can commit before Avalonia processes the click. - Implement
AvnTextInputMethod::Reset()to invoke a new delegate hook that clears preedit/marked state and discards marked text in the native input context. - Extend
AvnTextInputMethodDelegatewithresetInputMethodand implement it onAvnView.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| native/Avalonia.Native/src/OSX/AvnView.mm | Forwards mouse-down to the input context during composition and adds a reset hook to clear marked/preedit state. |
| native/Avalonia.Native/src/OSX/AvnTextInputMethodDelegate.h | Extends the delegate protocol with resetInputMethod used during client resets. |
| native/Avalonia.Native/src/OSX/AvnTextInputMethod.mm | Implements Reset() to call the delegate and trigger native IME state cleanup on focus/client changes. |
|
You can test this PR using the following package version. |
|
#19636 also appears to be the same issue |
|
I missed something. Korean preedit is always a single character, but Japanese and Chinese preedit can span multiple characters, so we must not commit the preedit when the user clicks inside it. We should only commit it when a point outside the preedit is clicked. |
|
You can test this PR using the following package version. |
|
We do not need to fix this as part of this PR. I have a dedicated PR for a more complete NSTextInputContext implementation that covers this as well. That PR is based on this PR. |
|
You can test this PR using the following package version. |
* fix(macOS): commit IME preedit when switching focus between textboxes Fixes #19964 * remove comment --------- Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
What does the pull request do?
Fixes two related macOS Korean IME issues where in-progress composition
(preedit) text was lost when focus moved away from a
TextBoxwhilecomposing — e.g. while typing Korean and then clicking another control or
switching focus between text boxes.
What is the current behavior?
On macOS, when a Korean IME composition is active (marked/preedit text is
shown) and the user moves focus away — by clicking another control or
focusing a different
TextBox— the composing text is silently discardedinstead of being committed. The half-composed characters are lost.
This happens because:
AvnTextInputMethod::Reset()was an empty no-op, so the native inputcontext was never told to finalize/clear its marked text when the
Avalonia input client changed.
NSTextInputContext, so the IME never got the chance to commit thecomposition before the click was handled.
What is the updated/expected behavior with this PR?
The active composition is committed (not dropped) when focus changes:
stale composition state.
To test:
TextBox(leave it mid-composition, with theunderlined preedit visible).
TextBox.TextBoxinsteadof being lost.
How was the solution implemented (if it's not obvious)?
AvnView: on a mouse button-down whilehasMarkedTextis true, forwardthe event to
[self inputContext] handleEvent:so the IME commits thein-progress composition before the click is processed.
AvnTextInputMethod::Reset()now calls a newresetInputMethoddelegatemethod on the view, which clears the preedit on the Avalonia client,
resets the marked range, and calls
discardMarkedTexton the inputcontext so no stale composition state leaks across focus changes.
resetInputMethoddeclaration toAvnTextInputMethodDelegate.Checklist
not covered by the automated test harness.
Breaking changes
None.
Obsoletions / Deprecations
None.
Fixed issues
Fixes #19964
Fixes #15183