Skip to content

AI-native design editor. Open-source Figma alternative.

refactor(app): derive command menu shortcuts

Danila Poyarkov0da23d552607
diff --git a/desktop/generated/menu.json b/desktop/generated/menu.json
index a59854eff..e2965e4c8 100644
--- a/desktop/generated/menu.json
+++ b/desktop/generated/menu.json
@@ -67,13 +67,11 @@
"items": [
{
"id": "edit.undo",
- "label": "Undo",
- "accelerator": "CmdOrCtrl+Z"
+ "label": "Undo"
},
{
"id": "edit.redo",
- "label": "Redo",
- "accelerator": "CmdOrCtrl+Shift+Z"
+ "label": "Redo"
},
{
"type": "separator"
@@ -95,21 +93,18 @@
},
{
"id": "selection.duplicate",
- "label": "Duplicate",
- "accelerator": "CmdOrCtrl+D"
+ "label": "Duplicate"
},
{
"id": "selection.delete",
- "label": "Delete",
- "accelerator": "Backspace"
+ "label": "Delete"
},
{
"type": "separator"
},
{
"id": "selection.selectAll",
- "label": "Select All",
- "accelerator": "CmdOrCtrl+A"
+ "label": "Select All"
}
]
},
@@ -118,18 +113,15 @@
"items": [
{
"id": "view.zoom100",
- "label": "Zoom to 100%",
- "accelerator": "CmdOrCtrl+0"
+ "label": "Zoom to 100%"
},
{
"id": "view.zoomFit",
- "label": "Zoom to Fit",
- "accelerator": "CmdOrCtrl+1"
+ "label": "Zoom to Fit"
},
{
"id": "view.zoomSelection",
- "label": "Zoom to Selection",
- "accelerator": "CmdOrCtrl+2"
+ "label": "Zoom to Selection"
},
{
"id": "zoom-in",
@@ -185,21 +177,18 @@
"items": [
{
"id": "selection.group",
- "label": "Group Selection",
- "accelerator": "CmdOrCtrl+G"
+ "label": "Group Selection"
},
{
"id": "selection.ungroup",
- "label": "Ungroup Selection",
- "accelerator": "CmdOrCtrl+Shift+G"
+ "label": "Ungroup Selection"
},
{
"type": "separator"
},
{
"id": "selection.createComponent",
- "label": "Create Component",
- "accelerator": "CmdOrCtrl+Alt+K"
+ "label": "Create Component"
},
{
"id": "selection.createComponentSet",
@@ -214,13 +203,11 @@
},
{
"id": "selection.bringToFront",
- "label": "Bring to Front",
- "accelerator": "]"
+ "label": "Bring to Front"
},
{
"id": "selection.sendToBack",
- "label": "Send to Back",
- "accelerator": "["
+ "label": "Send to Back"
}
]
},
@@ -249,8 +236,7 @@
"items": [
{
"id": "selection.wrapInAutoLayout",
- "label": "Wrap in Auto Layout",
- "accelerator": "Shift+A"
+ "label": "Wrap in Auto Layout"
},
{
"type": "separator"
diff --git a/src/app/shell/menu/schema.ts b/src/app/shell/menu/schema.ts
index 23345675f..c06994437 100644
--- a/src/app/shell/menu/schema.ts
+++ b/src/app/shell/menu/schema.ts
@@ -58,13 +58,11 @@ export const APP_MENU_SCHEMA = [
{
id: 'edit.undo',
label: 'Undo',
- shortcut: 'MOD+Z',
command: 'edit.undo'
},
{
id: 'edit.redo',
label: 'Redo',
- shortcut: 'MOD+SHIFT+Z',
command: 'edit.redo'
},
{ type: 'separator' },
@@ -74,20 +72,17 @@ export const APP_MENU_SCHEMA = [
{
id: 'selection.duplicate',
label: 'Duplicate',
- shortcut: 'MOD+D',
command: 'selection.duplicate'
},
{
id: 'selection.delete',
label: 'Delete',
- shortcut: '⌫',
command: 'selection.delete'
},
{ type: 'separator' },
{
id: 'selection.selectAll',
label: 'Select All',
- shortcut: 'MOD+A',
command: 'selection.selectAll'
}
]
@@ -98,19 +93,16 @@ export const APP_MENU_SCHEMA = [
{
id: 'view.zoom100',
label: 'Zoom to 100%',
- shortcut: 'MOD+0',
command: 'view.zoom100'
},
{
id: 'view.zoomFit',
label: 'Zoom to Fit',
- shortcut: 'MOD+1',
command: 'view.zoomFit'
},
{
id: 'view.zoomSelection',
label: 'Zoom to Selection',
- shortcut: 'MOD+2',
command: 'view.zoomSelection'
},
{ id: 'zoom-in', label: 'Zoom In', shortcut: 'MOD+=' },
@@ -143,20 +135,17 @@ export const APP_MENU_SCHEMA = [
{
id: 'selection.group',
label: 'Group Selection',
- shortcut: 'MOD+G',
command: 'selection.group'
},
{
id: 'selection.ungroup',
label: 'Ungroup Selection',
- shortcut: 'MOD+SHIFT+G',
command: 'selection.ungroup'
},
{ type: 'separator' },
{
id: 'selection.createComponent',
label: 'Create Component',
- shortcut: 'MOD+ALT+K',
command: 'selection.createComponent'
},
{
@@ -173,13 +162,11 @@ export const APP_MENU_SCHEMA = [
{
id: 'selection.bringToFront',
label: 'Bring to Front',
- shortcut: ']',
command: 'selection.bringToFront'
},
{
id: 'selection.sendToBack',
label: 'Send to Back',
- shortcut: '[',
command: 'selection.sendToBack'
}
]
@@ -198,7 +185,6 @@ export const APP_MENU_SCHEMA = [
{
id: 'selection.wrapInAutoLayout',
label: 'Wrap in Auto Layout',
- shortcut: 'SHIFT+A',
command: 'selection.wrapInAutoLayout'
},
{ type: 'separator' },
diff --git a/src/app/shell/menu/shortcut.ts b/src/app/shell/menu/shortcut.ts
index 9de2ccab6..a99790df6 100644
--- a/src/app/shell/menu/shortcut.ts
+++ b/src/app/shell/menu/shortcut.ts
@@ -1,4 +1,4 @@
-import { formatShortcut } from '@open-pencil/vue'
+import { editorCommandMetadata, formatShortcut } from '@open-pencil/vue'
import type { AppMenuActionItem, AppMenuEntry } from '@/app/shell/menu/schema'
import { APP_MENU_SCHEMA } from '@/app/shell/menu/schema'
@@ -10,7 +10,7 @@ function isActionItem(entry: AppMenuEntry): entry is AppMenuActionItem {
function findShortcutInEntries(entries: readonly AppMenuEntry[], id: string): string | undefined {
for (const entry of entries) {
if (!isActionItem(entry)) continue
- if (entry.id === id) return entry.shortcut
+ if (entry.id === id) return entry.shortcut ?? (entry.command ? editorCommandMetadata(entry.command).shortcut : undefined)
const shortcut = entry.sub ? findShortcutInEntries(entry.sub, id) : undefined
if (shortcut) return shortcut
}
diff --git a/tests/engine/app/shell/menu/schema.test.ts b/tests/engine/app/shell/menu/schema.test.ts
new file mode 100644
index 000000000..bcb9f612c
--- /dev/null
+++ b/tests/engine/app/shell/menu/schema.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, test } from 'bun:test'
+
+import type { AppMenuEntry } from '@/app/shell/menu/schema'
+import { APP_MENU_SCHEMA } from '@/app/shell/menu/schema'
+
+function actionItems(entries: readonly AppMenuEntry[]): AppMenuEntry[] {
+ const result: AppMenuEntry[] = []
+ for (const entry of entries) {
+ if ('type' in entry && entry.type === 'separator') continue
+ result.push(entry)
+ if (entry.sub) result.push(...actionItems(entry.sub))
+ }
+ return result
+}
+
+describe('APP_MENU_SCHEMA', () => {
+ test('does not duplicate shortcuts for command-backed entries', () => {
+ const duplicated = APP_MENU_SCHEMA.flatMap((group) =>
+ actionItems(group.items).filter((entry) => !('type' in entry) && entry.command && entry.shortcut)
+ )
+
+ expect(duplicated).toEqual([])
+ })
+})