Skip to content

Commit

Permalink
Make sure focus lost is delayed until IMM32 has finished up the compo…
Browse files Browse the repository at this point in the history
…sition on kill focus (#15907)
  • Loading branch information
Gillibald authored Jun 4, 2024
1 parent 2372590 commit 9c89dee
Showing 1 changed file with 18 additions and 1 deletion.
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

0 comments on commit 9c89dee

Please sign in to comment.