[Color Picker] Use escape key to exit colour editor UI (#10325)

* Use escape key to exit color editor UI

* Logic handling formatting
This commit is contained in:
Ben Constable 2021-03-22 09:15:47 +00:00 committed by GitHub
parent 612e9f8b99
commit 77d67f3599
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View file

@ -71,6 +71,25 @@ namespace ColorPicker.Helpers
_colorEditorWindow.Show();
}
public void HideColorPickerEditor()
{
if (_colorEditorWindow != null)
{
_colorEditorWindow.Hide();
}
}
public bool IsColorPickerEditorVisible()
{
if (_colorEditorWindow != null)
{
// Check if we are visible and on top. Using focus producing unreliable results the first time the picker is opened.
return _colorEditorWindow.Topmost && _colorEditorWindow.IsVisible;
}
return false;
}
public static void SetTopMost()
{
Application.Current.MainWindow.Topmost = false;

View file

@ -72,8 +72,16 @@ namespace ColorPicker.Keyboard
// ESC pressed
if (virtualCode == KeyInterop.VirtualKeyFromKey(Key.Escape))
{
_appStateHandler.HideColorPicker();
PowerToysTelemetry.Log.WriteEvent(new ColorPickerCancelledEvent());
if (_appStateHandler.IsColorPickerEditorVisible())
{
_appStateHandler.HideColorPickerEditor();
}
else
{
_appStateHandler.HideColorPicker();
PowerToysTelemetry.Log.WriteEvent(new ColorPickerCancelledEvent());
}
return;
}