From 980d27c91fcc9bdbdca617585776fc280fee4a36 Mon Sep 17 00:00:00 2001
From: Vishnu <vishnu@hexrfactory.com>
Date: Tue, 13 May 2025 11:04:12 +0530
Subject: [PATCH] Implement sidebar shortcut handling for visibility toggling;
 refactor existing shortcut logic for improved clarity

---
 .../utils/shortcutkeys/handleShortcutKeys.ts  | 48 ++++++++++---------
 1 file changed, 26 insertions(+), 22 deletions(-)

diff --git a/app/src/utils/shortcutkeys/handleShortcutKeys.ts b/app/src/utils/shortcutkeys/handleShortcutKeys.ts
index bb87970..c3346b8 100644
--- a/app/src/utils/shortcutkeys/handleShortcutKeys.ts
+++ b/app/src/utils/shortcutkeys/handleShortcutKeys.ts
@@ -42,6 +42,7 @@ const KeyPressListener: React.FC = () => {
         };
         const module = modules[keyCombination];
         if (module && !toggleView) {
+            console.log("hi");
             setActiveTool("cursor");
             setActiveSubTool("cursor");
             if (module === "market") setToggleUI(false, false);
@@ -106,6 +107,29 @@ const KeyPressListener: React.FC = () => {
     };
 
 
+    const handleSidebarShortcuts = (key: string) => {
+        if (activeModule !== "market") {
+            if (key === "Ctrl+\\") {
+                if (toggleUILeft === toggleUIRight) {
+                    setToggleUI(!toggleUILeft, !toggleUIRight);
+                }
+                else {
+                    setToggleUI(true, true);
+                }
+                return;
+            }
+            if (key === "Ctrl+]") {
+                    setToggleUI(toggleUILeft, !toggleUIRight);
+                    return;
+            }
+            if (key === "Ctrl+[") {
+                    setToggleUI(!toggleUILeft, toggleUIRight);
+                    return;
+            }
+        }
+    }
+
+
     const handleKeyPress = (event: KeyboardEvent) => {
         if (isTextInput(document.activeElement)) return;
 
@@ -114,28 +138,8 @@ const KeyPressListener: React.FC = () => {
 
         event.preventDefault();
 
-        if (keyCombination === "Ctrl+\\") {
-            if (toggleUILeft === toggleUIRight) {
-                setToggleUI(!toggleUILeft, !toggleUIRight);
-            }
-            else {
-                activeModule !== "market" && setToggleUI(true, true);
-            }
-            return;
-        }
-        if (keyCombination === "Ctrl+]") {
-            if (activeModule !== "market") {
-                setToggleUI(toggleUILeft, !toggleUIRight);
-            }
-            return;
-        }
-        if (keyCombination === "Ctrl+[") {
-            if (activeModule !== "market") {
-                setToggleUI(!toggleUILeft, toggleUIRight);
-            }
-            return;
-        }
-
+        // Shortcuts specific for sidebar visibility toggle and others specific to sidebar if added
+        handleSidebarShortcuts(keyCombination);
         // Active module selection (builder, simulation, etc.)
         handleModuleSwitch(keyCombination);
         // Common editing tools: cursor | delete | free-hand