diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs index 09d2aa4d54de..d7d1945493c6 100644 --- a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs +++ b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs @@ -230,7 +230,7 @@ internal void RegisterWindowHandle(System.Windows.Interop.HwndSource hwndSource) public bool HandleEnterPressed() { - if (!IsColorPickerVisible()) + if (!_colorPickerShown) { return false; } @@ -241,14 +241,13 @@ public bool HandleEnterPressed() public bool HandleEscPressed() { - if (!BlockEscapeKeyClosingColorPickerEditor) + if (!BlockEscapeKeyClosingColorPickerEditor + && (_colorPickerShown || (_colorEditorWindow != null && _colorEditorWindow.IsActive))) { return EndUserSession(); } - else - { - return false; - } + + return false; } internal void MoveCursor(int xOffset, int yOffset) diff --git a/src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs b/src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs index 208f139ae8f1..d6defaacb2c2 100644 --- a/src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs +++ b/src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs @@ -70,17 +70,10 @@ private void Hook_KeyboardPressed(object sender, GlobalKeyboardHookEventArgs e) var virtualCode = e.KeyboardData.VirtualCode; // ESC pressed - if (virtualCode == KeyInterop.VirtualKeyFromKey(Key.Escape) - && e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyDown - ) + if (virtualCode == KeyInterop.VirtualKeyFromKey(Key.Escape) && e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyDown) { - if (_appStateHandler.IsColorPickerVisible() - || !AppStateHandler.BlockEscapeKeyClosingColorPickerEditor - ) - { - e.Handled = _appStateHandler.EndUserSession(); - return; - } + e.Handled = _appStateHandler.HandleEscPressed(); + return; } if ((virtualCode == KeyInterop.VirtualKeyFromKey(Key.Space) || virtualCode == KeyInterop.VirtualKeyFromKey(Key.Enter)) && (e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyDown))