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 and grokys committed Jun 12, 2024
1 parent 21ee489 commit f9be42b
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 @@ -680,7 +682,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 @@ -725,6 +735,13 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam,
{
Imm32InputMethod.Current.HandleCompositionEnd();

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

_killFocusRequested = false;
}

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

0 comments on commit f9be42b

Please sign in to comment.