Skip to content

Commit

Permalink
[Color Picker] Use escape key to exit colour editor UI (#10325)
Browse files Browse the repository at this point in the history
* Use escape key to exit color editor UI

* Logic handling formatting
  • Loading branch information
BenConstable9 committed Mar 22, 2021
1 parent 612e9f8 commit 77d67f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ public void ShowColorPickerEditor()
_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;
Expand Down
12 changes: 10 additions & 2 deletions src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,16 @@ private void Hook_KeyboardPressed(object sender, GlobalKeyboardHookEventArgs e)
// 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;
}

Expand Down

0 comments on commit 77d67f3

Please sign in to comment.