From 2074db6f78ed80d70acaf9a285c6fd11950a1ae1 Mon Sep 17 00:00:00 2001 From: Jacob Poteet <64765148+JacobPoteet@users.noreply.github.com> Date: Sat, 10 Feb 2024 13:38:33 -0500 Subject: [PATCH] Refactor KeyboardShortcutManager.cs for improved readability and maintainability The code changes in this commit simplify the logic in the `OnAcceleratorKeyActivated` method of `KeyboardShortcutManager.cs`. - Replaced nested if-else statements with concise conditional expressions - Removed redundant checks for `altPressed` and `controlKeyPressed` - Consolidated return statements based on key combinations --- .../Common/KeyboardShortcutManager.cs | 45 +++---------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/src/Calculator/Common/KeyboardShortcutManager.cs b/src/Calculator/Common/KeyboardShortcutManager.cs index 141298bb..c3fe992d 100644 --- a/src/Calculator/Common/KeyboardShortcutManager.cs +++ b/src/Calculator/Common/KeyboardShortcutManager.cs @@ -747,48 +747,17 @@ namespace CalculatorApp { int viewId = Utilities.GetWindowId(); - if (controlKeyPressed) + if (controlKeyPressed && !altPressed) { - if (altPressed) - { - return null; - } - else - { - if (shiftKeyPressed) - { - return s_VirtualKeyControlShiftChordsForButtons[viewId]; - } - else - { - return s_VirtualKeyControlChordsForButtons[viewId]; - } - } + return shiftKeyPressed ? s_VirtualKeyControlShiftChordsForButtons[viewId] : s_VirtualKeyControlChordsForButtons[viewId]; + } + else if (altPressed && !controlKeyPressed) + { + return shiftKeyPressed ? null : s_VirtualKeyAltChordsForButtons[viewId]; } else { - if (altPressed) - { - if (shiftKeyPressed) - { - return null; - } - else - { - return s_VirtualKeyAltChordsForButtons[viewId]; - } - } - else - { - if (shiftKeyPressed) - { - return s_VirtualKeyShiftChordsForButtons[viewId]; - } - else - { - return s_virtualKey[viewId]; - } - } + return shiftKeyPressed ? s_VirtualKeyShiftChordsForButtons[viewId] : s_virtualKey[viewId]; } }