Fix issue 1782

This commit is contained in:
Jesus Baylon 2022-06-10 15:29:59 -07:00
commit 54c67a4f9e
2 changed files with 16 additions and 25 deletions

View file

@ -322,16 +322,22 @@ namespace CalculatorApp
} }
public static void DisableShortcuts(bool disable) public static void DisableShortcuts(bool disable)
{
//deferredEnableShortcut is being used to prevent the mode change from happening before the user input has processed
if (s_keyHandlerCount > && !disable)
{
s_deferredEnableShortcut = true;
}
else
{ {
int viewId = Utilities.GetWindowId(); int viewId = Utilities.GetWindowId();
if (s_fDisableShortcuts.ContainesKey(viewId))
if (s_fDisableShortcuts.ContainsKey(viewId))
{ {
s_fDisableShortcuts[viewId] = disable; s_fDisableShortcuts[viewId] = disable;
} }
HonorShortcuts(!disable); HonorShortcuts(!disable);
} }
}
public static void UpdateDropDownState(bool isOpen) public static void UpdateDropDownState(bool isOpen)
{ {
@ -631,7 +637,6 @@ namespace CalculatorApp
private static void OnCharacterReceivedHandler(CoreWindow sender, CharacterReceivedEventArgs args) private static void OnCharacterReceivedHandler(CoreWindow sender, CharacterReceivedEventArgs args)
{ {
int viewId = Utilities.GetWindowId(); int viewId = Utilities.GetWindowId();
bool hit = s_fHonorShortcuts.TryGetValue(viewId, out var currentHonorShortcuts); bool hit = s_fHonorShortcuts.TryGetValue(viewId, out var currentHonorShortcuts);
if (!hit || currentHonorShortcuts) if (!hit || currentHonorShortcuts)
@ -722,22 +727,9 @@ namespace CalculatorApp
s_keyHandlerCount--; s_keyHandlerCount--;
if (s_keyHandlerCount == 0 && s_deferredEnableShortcut) if (s_keyHandlerCount == 0 && s_deferredEnableShortcut)
{ {
KeyboardShortcutManager.DisableShortcuts(false);//shortcuts enabled DisableShortcuts(false);
s_deferredEnableShortcut = false; s_deferredEnableShortcut = false;
} }
}
public static void TryEnableShortcut()
{
if (s_keyHandlerCount > 0)
{
s_deferredEnableShortcut = true;
}
else
{
KeyboardShortcutManager.DisableShortcuts(false);
}
} }
private static void OnAcceleratorKeyActivated(CoreDispatcher dispatcher, AcceleratorKeyEventArgs args) private static void OnAcceleratorKeyActivated(CoreDispatcher dispatcher, AcceleratorKeyEventArgs args)
@ -858,9 +850,8 @@ namespace CalculatorApp
//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 int s_keyHandlerCount; private static bool s_deferredEnableShortcut = false;
private static bool s_deferredEnableShortcut;
} }
} }
} }

View file

@ -201,7 +201,7 @@ namespace CalculatorApp
ViewMode newValue = m_model.Mode; ViewMode newValue = m_model.Mode;
ViewMode previousMode = m_model.PreviousMode; ViewMode previousMode = m_model.PreviousMode;
KeyboardShortcutManager.TryEnableShortcut(); KeyboardShortcutManager.DisableShortcuts(false);
if (newValue == ViewMode.Standard) if (newValue == ViewMode.Standard)
{ {