From 21aa49cefb817afc05e373e962e436847784a79f Mon Sep 17 00:00:00 2001 From: PesBandi <127593627+PesBandi@users.noreply.github.com> Date: Tue, 15 Apr 2025 05:15:41 +0200 Subject: [PATCH] [ColorPicker]Only close on escape if focused (#37895) --- .../ColorPickerUI/Helpers/AppStateHandler.cs | 11 +++++------ .../ColorPickerUI/Keyboard/KeyboardMonitor.cs | 13 +++---------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs index 4940bd75e3..b3350702c7 100644 --- a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs +++ b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs @@ -222,7 +222,7 @@ namespace ColorPicker.Helpers public bool HandleEnterPressed() { - if (!IsColorPickerVisible()) + if (!_colorPickerShown) { return false; } @@ -233,14 +233,13 @@ namespace ColorPicker.Helpers 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 208f139ae8..d6defaacb2 100644 --- a/src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs +++ b/src/modules/colorPicker/ColorPickerUI/Keyboard/KeyboardMonitor.cs @@ -70,17 +70,10 @@ namespace ColorPicker.Keyboard 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))