From e778b29b564cf3d54c11e9b3d5446343edad74dc Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Fri, 10 Oct 2025 22:38:28 +0200 Subject: [PATCH] feat: centralize keyboard shortcuts through shortcut manager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All keyboard shortcut labels in the MenuBar now come from the centralized keyboard shortcut manager via the new useShortcutLabels hook, eliminating hardcoded duplicates. Changes: - Add useShortcutLabels hook for retrieving formatted shortcut labels - Update MenuBar to use dynamic shortcut labels from manager - Platform-aware display (Cmd on Mac, Ctrl elsewhere) - Shortcuts automatically update if changed in manager - Fix MUI icon fontSize prop issue in LeftPanel 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/components/Menu/MenuBar.tsx | 26 ++++++++++++---- src/components/Panels/LeftPanel.tsx | 4 +-- src/hooks/useShortcutLabels.ts | 48 +++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 src/hooks/useShortcutLabels.ts diff --git a/src/components/Menu/MenuBar.tsx b/src/components/Menu/MenuBar.tsx index d4951f4..3a90109 100644 --- a/src/components/Menu/MenuBar.tsx +++ b/src/components/Menu/MenuBar.tsx @@ -6,6 +6,7 @@ import DocumentManager from '../Workspace/DocumentManager'; import NodeTypeConfigModal from '../Config/NodeTypeConfig'; import EdgeTypeConfigModal from '../Config/EdgeTypeConfig'; import { useConfirm } from '../../hooks/useConfirm'; +import { useShortcutLabels } from '../../hooks/useShortcutLabels'; /** * MenuBar Component @@ -30,6 +31,7 @@ const MenuBar: React.FC = ({ onOpenHelp, onFitView, onSelectAll }) const [showEdgeConfig, setShowEdgeConfig] = useState(false); const menuRef = useRef(null); const { confirm, ConfirmDialogComponent } = useConfirm(); + const { getShortcutLabel } = useShortcutLabels(); const { createDocument, @@ -168,7 +170,9 @@ const MenuBar: React.FC = ({ onOpenHelp, onFitView, onSelectAll }) className="w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 flex items-center justify-between" > New Document - Ctrl+N + {getShortcutLabel('new-document') && ( + {getShortcutLabel('new-document')} + )}
@@ -198,7 +204,9 @@ const MenuBar: React.FC = ({ onOpenHelp, onFitView, onSelectAll }) className="w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 flex items-center justify-between" > Export Document - Ctrl+S + {getShortcutLabel('save-document') && ( + {getShortcutLabel('save-document')} + )} )} @@ -330,7 +342,9 @@ const MenuBar: React.FC = ({ onOpenHelp, onFitView, onSelectAll }) className="w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 flex items-center justify-between" > Keyboard Shortcuts - ? + {getShortcutLabel('show-help') && ( + {getShortcutLabel('show-help')} + )} )} diff --git a/src/components/Panels/LeftPanel.tsx b/src/components/Panels/LeftPanel.tsx index 4590e2e..694260b 100644 --- a/src/components/Panels/LeftPanel.tsx +++ b/src/components/Panels/LeftPanel.tsx @@ -125,8 +125,8 @@ const LeftPanel = ({ onDeselectAll, onAddNode }: LeftPanelProps) => { title={nodeType.description} > {IconComponent ? ( -
- +
+
) : (
{ + const allShortcuts = shortcuts.getAllShortcuts(); + const shortcut = allShortcuts.find((s) => s.id === shortcutId); + + // Return null if shortcut doesn't exist or is disabled + if (!shortcut || shortcut.enabled === false) { + return null; + } + + return shortcuts.formatShortcut(shortcut); + }, + [shortcuts] + ); + + return { getShortcutLabel }; +}