Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Win] Fix composition on focus change #15907

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Avalonia.Win32
{
internal partial class WindowImpl
{
private bool _killFocusRequested;

[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation",
Justification = "Using Win32 naming for consistency.")]
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "We do .NET COM interop availability checks")]
Expand Down Expand Up @@ -718,7 +720,15 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam,
}

case WindowsMessage.WM_KILLFOCUS:
LostFocus?.Invoke();
if (Imm32InputMethod.Current.IsComposing)
{
_killFocusRequested = true;
}
else
{
LostFocus?.Invoke();
}

break;

case WindowsMessage.WM_INPUTLANGCHANGE:
Expand Down Expand Up @@ -763,6 +773,13 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam,
{
Imm32InputMethod.Current.HandleCompositionEnd(timestamp);

if (_killFocusRequested)
{
LostFocus?.Invoke();

_killFocusRequested = false;
}

return IntPtr.Zero;
}
case WindowsMessage.WM_GETOBJECT:
Expand Down
Loading