Implement sidebar shortcut handling for visibility toggling; refactor existing shortcut logic for improved clarity

This commit is contained in:
Vishnu 2025-05-13 11:04:12 +05:30
parent 34aa9b9dec
commit 980d27c91f
1 changed files with 26 additions and 22 deletions

View File

@ -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