Support Chinese IME preedit and fix related bugs - #592
Conversation
- Add PreeditLayer to render IME composition text at caret position with underline - Enable SupportsPreedit in TextAreaTextInputMethodClient - Implement SetPreeditText(string) and SetPreeditText(string, int?) overloads - Clear preedit on text input, focus loss, Escape key, and document change - Update preedit position when caret moves Fixes Chinese IME input where composition text was not displayed.
- Add automated test suite verifying IME client setup - Tests: SupportsPreedit, PreeditLayer, SetPreeditText, ClearPreedit - All 8 tests pass
…rovided When the platform calls SetPreeditText(string) without a cursorOffset, the cursor was not rendered at all. Now defaults to rendering at the end of the composition text, which matches standard IME behavior.
Changelog: ## Bug Fixes ### OnPaste document update lock (EditingCommandHandler.cs) - The async void OnPaste method could leave the document in a permanent BeginUpdate state if ReplaceSelectionWithText threw an exception after the clipboard await. Wrapped the entire operation in try/finally to ensure EndUpdate is always called. - Also added null checks for clipboard access to prevent NRE. ### ICommand.CanExecuteChanged never fires (RoutedCommand.cs) - The CanExecuteChanged event had empty add/remove accessors, meaning UI elements bound to commands would never re-evaluate their enabled state. Implemented proper event storage and added CommandManager class with InvalidateRequerySuggested() to trigger re-evaluation. - Focus changes now automatically trigger command re-evaluation. ### InvalidateCursor dead code (TextView.cs) - The InvalidateCursor method scheduled a dispatcher callback that did nothing (MouseDevice.Instance.UpdateCursor() was commented out). - Replaced with clean no-op implementation with documentation explaining that Avalonia handles cursor updates automatically via the Cursor property. Removed unused _invalidCursor field. ## CI Fixes ### Artifact name invalid for branches with slashes (build-nuget.yml) - Branch names containing '/' (e.g. bugfixes/enhancements, feature/xxx) caused upload-artifact to fail. Added a sanitize step that replaces '/' with '-' in the artifact name.
|
Hi @Timskt — you found the way through first, and I was able to fix my own application by following your work. Thank you. I would like to report that it also solves the problem for Japanese IME, with numbers, in case that is useful for review. I maintain TextSS, a Japanese freeware bulk text-replacement tool that I have been releasing for 28 years. I recently ported it from VB.NET / .NET Framework to C# / .NET 10 + Avalonia, and AvaloniaEdit's missing preedit was the one blocker I could not solve: with Japanese input you cannot see what you are typing until you commit it, which is fatal for a Japanese tool. I released 6.00 with a workaround — a second, hand-made text box sitting beside the editor — rather than a fix. Then I found this PR. It is written for Chinese IME, but the implementation is language-independent and worked for Japanese exactly as it is. Environment
What works with this PR as it is — on all three platforms
Point 3 I checked numerically rather than by eye: while composing 9 characters at the end of a 58-character line, the status readout stayed at Five things I had to add on top — none of them defects in this PRThree of them are behaviour outside this PR's scope, and two only show up with the long, whole-sentence conversions that Japanese input produces. I list them because anyone adopting this PR for Japanese will meet them.
Measured for 4: committing 24 characters moved the horizontal offset only 384.4 → 386.9 px while the caret sat at x = 1204.2 in a viewport 981.3 px wide; the extent after the commit had grown to 1670.6. Measured for 5: 3 px. Still openPer-clause underlines. Japanese IMEs distinguish the clause currently being converted from the rest, but CodeEverything above is in a small demo application together with the patched fork, published so that it can be reproduced: https://github.com/YamashitaY-TextSS/avaloniaedit-ime-test The places I changed on top of this PR are marked I also wrote the whole investigation up in English, as a chapter of my porting diary: https://textss.sakura.ne.jp/en/devlog11-avaloniaedit.html If this PR is merged, I would be glad to submit the five additions above as a follow-up PR. They sit on top of this one, so that order is the one that makes sense. One more note: I ran into the problem your #591 fixes as well — the built-in Thank you again. Without this pull request my application would still have that hole in it. |
I am very glad that my PR can help everyone. Regarding the other issues beyond PR that you mentioned, I have already resolved them based on the latest fork of the Avalonianedit repository in my personal latest repository and applied it to my actual IM project. This is a software similar to WeChat chat, and its stability has been verified by at least 100+users. You can try my warehouse: https://github.com/Timskt/AvaloniaEdit.RichTextInput See if it can solve your other problems. Its usage is consistent with the official. |
|
Thank you for the quick reply, and for pointing me at your repository.
I would very much like to try it. When I have some time I will build a small demo against it, the same way I built one for this PR, and see how it behaves with Japanese IME — in particular the five points I listed. I will report back here with what I find. Thank you again for coming back to this so quickly. |
|
Hi @Timskt — thank you again for pointing me to What worked straight away
Suggestions, from the Japanese-input angle
How I measured — Windows 11 at 150 % scaling, .NET 10, Avalonia 12.1.1, your And one thought, if I may. Since you have already solved these behaviours on top of the latest AvaloniaEdit, would you consider sending them upstream as well — into this PR or as a follow-up? Many people need only a code editor rather than rich IM input, and Chinese, Japanese and Korean users all run into the same wall; your pull requests are already the closest thing to a fix that exists. Thank you again for the work, and for sharing it. |
Summary
Implements Chinese IME preedit (composition) support for TextArea, along with related bug fixes and improvements.
Changes
PreeditLayerfor rendering IME preedit text with underline styling in TextAreacursorOffsetis not providedRelated
Test plan