Browse Source

Merge pull request #765 from VitalElement/fixes/allow-alt-modifier-for-text-input

Fixes/allow alt modifier for text input
drawing-context-hack
Steven Kirk 9 years ago
committed by GitHub
parent
commit
ee8dbe502e
  1. 25
      src/Avalonia.Input/AccessKeyHandler.cs

25
src/Avalonia.Input/AccessKeyHandler.cs

@ -43,6 +43,16 @@ namespace Avalonia.Input
/// </summary>
private bool _ignoreAltUp;
/// <summary>
/// Whether the AltKey is down.
/// </summary>
private bool _altIsDown;
/// <summary>
/// Element to restore folowing AltKey taking focus.
/// </summary>
private IInputElement _restoreFocusElement;
/// <summary>
/// Gets or sets the window's main menu.
/// </summary>
@ -110,8 +120,14 @@ namespace Avalonia.Input
{
if (e.Key == Key.LeftAlt)
{
_altIsDown = true;
if (MainMenu == null || !MainMenu.IsOpen)
{
// TODO: Use FocusScopes to store the current element and restore it when context menu is closed.
// 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;
@ -121,11 +137,18 @@ namespace Avalonia.Input
// 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.
e.Handled = true;
}
else if (_altIsDown)
{
_ignoreAltUp = true;
}
}
/// <summary>
@ -179,6 +202,8 @@ namespace Avalonia.Input
switch (e.Key)
{
case Key.LeftAlt:
_altIsDown = false;
if (_ignoreAltUp)
{
_ignoreAltUp = false;

Loading…
Cancel
Save