Fix the captured access key in the result box

* Fix issue #1782

* Fixed issue 1782

* Fix issue 1782

* Fix issue #1782

* Fix Issue #1782

Co-authored-by: Jesus Baylon <t-jbaylon@microsoft.com>
This commit is contained in:
jbaylon3 2022-06-13 19:03:40 -07:00 committed by GitHub
parent 410dce76bf
commit 6430551167
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -249,6 +249,7 @@ internal static void Initialize()
var coreWindow = Window.Current.CoreWindow; var coreWindow = Window.Current.CoreWindow;
coreWindow.CharacterReceived += OnCharacterReceivedHandler; coreWindow.CharacterReceived += OnCharacterReceivedHandler;
coreWindow.KeyDown += OnKeyDownHandler; coreWindow.KeyDown += OnKeyDownHandler;
coreWindow.KeyUp += OnKeyUpHandler;
coreWindow.Dispatcher.AcceleratorKeyActivated += OnAcceleratorKeyActivated; coreWindow.Dispatcher.AcceleratorKeyActivated += OnAcceleratorKeyActivated;
KeyboardShortcutManager.RegisterNewAppViewId(); KeyboardShortcutManager.RegisterNewAppViewId();
} }
@ -322,14 +323,20 @@ public static void HonorShortcuts(bool allow)
public static void DisableShortcuts(bool disable) public static void DisableShortcuts(bool disable)
{ {
int viewId = Utilities.GetWindowId(); //deferredEnableShortcut is being used to prevent the mode change from happening before the user input has processed
if (s_keyHandlerCount > 0 && !disable)
if (s_fDisableShortcuts.ContainsKey(viewId))
{ {
s_fDisableShortcuts[viewId] = disable; s_deferredEnableShortcut = true;
}
else
{
int viewId = Utilities.GetWindowId();
if (s_fDisableShortcuts.ContainsKey(viewId))
{
s_fDisableShortcuts[viewId] = disable;
}
HonorShortcuts(!disable);
} }
HonorShortcuts(!disable);
} }
public static void UpdateDropDownState(bool isOpen) public static void UpdateDropDownState(bool isOpen)
@ -644,6 +651,8 @@ private static void OnCharacterReceivedHandler(CoreWindow sender, CharacterRecei
private static void OnKeyDownHandler(CoreWindow sender, KeyEventArgs args) private static void OnKeyDownHandler(CoreWindow sender, KeyEventArgs args)
{ {
s_keyHandlerCount++;
if (args.Handled) if (args.Handled)
{ {
return; return;
@ -714,6 +723,16 @@ private static void OnKeyDownHandler(CoreWindow sender, KeyEventArgs args)
} }
} }
private static void OnKeyUpHandler(CoreWindow sender, KeyEventArgs args)
{
s_keyHandlerCount--;
if (s_keyHandlerCount == 0 && s_deferredEnableShortcut)
{
DisableShortcuts(false);
s_deferredEnableShortcut = false;
}
}
private static void OnAcceleratorKeyActivated(CoreDispatcher dispatcher, AcceleratorKeyEventArgs args) private static void OnAcceleratorKeyActivated(CoreDispatcher dispatcher, AcceleratorKeyEventArgs args)
{ {
if (args.KeyStatus.IsKeyReleased) if (args.KeyStatus.IsKeyReleased)
@ -831,6 +850,9 @@ private static void Insert<Tkey, TValue>(SortedDictionary<Tkey, List<TValue>> de
//private static Concurrency.reader_writer_lock s_keyboardShortcutMapLock; //private static Concurrency.reader_writer_lock s_keyboardShortcutMapLock;
private static readonly object s_keyboardShortcutMapLockMutex = new object(); private static readonly object s_keyboardShortcutMapLockMutex = new object();
private static int s_keyHandlerCount = 0;
private static bool s_deferredEnableShortcut = false;
} }
} }
} }