AI-native design editor. Open-source Figma alternative.
fix(keyboard): route zoom shortcuts to canvas
7ot0m3ec6c42f0e579
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 31a51cbfa..19812c35d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -40,6 +40,7 @@### Fixed+- Route browser Command/Ctrl plus and minus shortcuts to canvas zoom instead of page zoom.- Resolve `$name` references in imported `.pen` fills, stroke fills, font families, dimensions, and spacing without requiring a `--` prefix. (#563)- Prevent the stock photo tool from replacing text, lines, structural layers, or containers with content while supporting closed shape geometry.- Preserve explicit text alignment metadata on imported Figma vectors across save and reload.diff --git a/src/app/shell/keyboard/registry.ts b/src/app/shell/keyboard/registry.tsindex 39cc0032e..7237d3242 100644--- a/src/app/shell/keyboard/registry.ts+++ b/src/app/shell/keyboard/registry.ts@@ -138,6 +138,24 @@ export function registerKeyboardShortcuts(options: KeyboardShortcutOptions) {run: () => openSettingsDialog(),global: true},+ {+ id: 'zoom-in',+ keys: [appMenuTinykeysShortcut('zoom-in') ?? '$mod+Equal', '$mod+Shift+Equal'],+ run: ({ store }) => {+ const center = store.viewportScreenCenter()+ store.applyZoom(-100, center.x, center.y)+ },+ global: true+ },+ {+ id: 'zoom-out',+ keys: appMenuTinykeysShortcut('zoom-out') ?? '$mod+Minus',+ run: ({ store }) => {+ const center = store.viewportScreenCenter()+ store.applyZoom(100, center.x, center.y)+ },+ global: true+ },{id: 'close-tab',keys: appMenuTinykeysShortcut('close') ?? '$mod+KeyW',diff --git a/tests/e2e/keyboard/shortcuts.spec.ts b/tests/e2e/keyboard/shortcuts.spec.tsindex 4b9206d04..e3939b836 100644--- a/tests/e2e/keyboard/shortcuts.spec.ts+++ b/tests/e2e/keyboard/shortcuts.spec.ts@@ -321,6 +321,48 @@ test.describe('opacity shortcuts', () => {})test.describe('zoom shortcuts', () => {+ test('⌘= and ⌘- zoom the canvas and prevent browser defaults', async () => {+ const result = await editor.page.evaluate(() => {+ const store = window.openPencil?.getStore?.()+ if (!store) throw new Error('OpenPencil store not initialized')+ store.zoomTo100()++ const modifier = /Mac|iPod|iPhone|iPad/.test(navigator.platform)+ ? { metaKey: true }+ : { ctrlKey: true }+ const zoomInEvent = new KeyboardEvent('keydown', {+ key: '=',+ code: 'Equal',+ ...modifier,+ bubbles: true,+ cancelable: true+ })+ window.dispatchEvent(zoomInEvent)+ const zoomedIn = store.state.zoom++ const zoomOutEvent = new KeyboardEvent('keydown', {+ key: '-',+ code: 'Minus',+ ...modifier,+ bubbles: true,+ cancelable: true+ })+ window.dispatchEvent(zoomOutEvent)++ return {+ zoomInPrevented: zoomInEvent.defaultPrevented,+ zoomOutPrevented: zoomOutEvent.defaultPrevented,+ zoomedIn,+ zoomedOut: store.state.zoom+ }+ })++ expect(result.zoomInPrevented).toBe(true)+ expect(result.zoomOutPrevented).toBe(true)+ expect(result.zoomedIn).toBeGreaterThan(1)+ expect(result.zoomedOut).toBeLessThan(result.zoomedIn)+ })+test('⌘0 zooms to 100%', async () => {await editor.canvas.clearCanvas()await editor.canvas.drawRect(100, 100, 60, 60)