AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
24.7k stars 2.14k forks source link

IME Candidate Window wrong behavior #15437

Open evhenii-komar opened 3 months ago

evhenii-komar commented 3 months ago

Describe the bug

The IME candidate window isn't closed if you click outside of it and in the same control it is used for. I develop custom control and found the only way to make the candidate window close is to put <AvaloniaAccessUnstablePrivateApis>true</AvaloniaAccessUnstablePrivateApis> into the <PropertyGroup> section of your project '.csproj' file and use this code inside of your Control to close it programmatically:

ITextInputMethodImpl inputMethod = (VisualRoot as ITextInputMethodRoot)?.InputMethod;
inputMethod.Reset();

But this way uses unstable private API so it isn't a confident solution. I've checked the behavior in other frameworks like WinForms, and WPF, in Windows elements like Explorer, and Notepad, and browsers like Chrome and Edge. All of them close the IME Candidate Window if you click outside of the candidate window even if you click the focused element the candidate window was opened for.

To Reproduce

The IME Candidate Window wasn't hidden.

Expected behavior

The IME Candidate Window is hidden.

Avalonia version

11.0.10

OS

Windows

Additional context

No response

Gillibald commented 3 months ago

Ime should be reset after focus change/loss

Gillibald commented 3 months ago

We might be able to change this by introducing a way to cancel current composition. What happens with the current composition. Is it committed as is or discarded?

evhenii-komar commented 3 months ago

Ime should be reset after focus change/loss

Yes, it is one of the reasons that should reset it but not the only expected. In checked frameworks, Windows elements, and browsers I mentioned above the focus loss isn't the only reason to reset Ime. The clicking anywhere outside the candidate window even on the surface of the focused control is the reason too. It can be checked by opening any element of Windows or browser. But, if it is the Avalonia behavior I would like to have a legal way to close it programmatically for my control.

We might be able to change this by introducing a way to cancel current composition. What happens with the current composition. Is it committed as is or discarded?

If you mean what will happen if I use this code to close the composition:

            ITextInputMethodImpl inputMethod = (VisualRoot as ITextInputMethodRoot)?.InputMethod;
            inputMethod?.Reset();

then it is discarded but I can avoid this by saving the last preedit text. I just need the candidate window to be hidden automatically if the user clicks outside of it. In this case, the text shouldn't be discarded. In WPF, WinForms etc. it isn't discarded. Or, the API to close it would be an option too.