From 3fea4d34f18a72a51f7691a6be523b9a934b353f Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Tue, 11 Oct 2016 21:48:36 +0100 Subject: [PATCH] Restore focus of input element after alt-key has stolen focus. --- src/Avalonia.Input/AccessKeyHandler.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Input/AccessKeyHandler.cs b/src/Avalonia.Input/AccessKeyHandler.cs index b23cdf550d..7b88fe18f3 100644 --- a/src/Avalonia.Input/AccessKeyHandler.cs +++ b/src/Avalonia.Input/AccessKeyHandler.cs @@ -48,6 +48,11 @@ namespace Avalonia.Input /// private bool _altIsDown; + /// + /// Element to restore folowing AltKey taking focus. + /// + private IInputElement _restoreFocusElement; + /// /// Gets or sets the window's main menu. /// @@ -119,15 +124,21 @@ namespace Avalonia.Input if (MainMenu == null || !MainMenu.IsOpen) { + // Save currently focused input element. + _restoreFocusElement = FocusManager.Instance.Current; + // When Alt is pressed without a main menu, or with a closed main menu, show // access key markers in the window (i.e. "_File"). - _owner.ShowAccessKeys = _showingAccessKeys = true; + _owner.ShowAccessKeys = _showingAccessKeys = true; } else { // If the Alt key is pressed and the main menu is open, close the main menu. CloseMenu(); _ignoreAltUp = true; + + _restoreFocusElement?.Focus(); + _restoreFocusElement = null; } // We always handle the Alt key.