From e118ad632aa545fc8a1b5047b9e1adbdb993be1e Mon Sep 17 00:00:00 2001 From: Hiren Kangad Date: Sat, 14 Mar 2026 11:22:29 +0530 Subject: [PATCH] feat: block rotate/flip for pdf-page in context menu and shortcuts --- frontend/src/canvas/context-menu-items.ts | 8 +++---- frontend/src/canvas/shortcut-definitions.ts | 24 +++++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/frontend/src/canvas/context-menu-items.ts b/frontend/src/canvas/context-menu-items.ts index f1f581d..a6897e4 100644 --- a/frontend/src/canvas/context-menu-items.ts +++ b/frontend/src/canvas/context-menu-items.ts @@ -157,10 +157,10 @@ export function buildContextMenuItems(ctx: MenuContext): MenuItem[] { { label: '', shortcut: '', onClick: () => {}, divider: true }, // -- Image -- - { label: 'Flip Horizontal', shortcut: 'Alt+Shift+H', onClick: () => { ops.flipHorizontal(selected); selection?.transformBox.update(selected); ctx.onChange(ids); }, disabled: !hasSel }, - { label: 'Flip Vertical', shortcut: 'Alt+Shift+V', onClick: () => { ops.flipVertical(selected); selection?.transformBox.update(selected); ctx.onChange(ids); }, disabled: !hasSel }, - { label: 'Rotate Clockwise', shortcut: 'R', onClick: () => { ops.rotate90(selected, true); selection?.transformBox.update(selected); ctx.onChange(ids); }, disabled: !hasSel }, - { label: 'Rotate Counter-Clockwise', shortcut: 'Shift+R', onClick: () => { ops.rotate90(selected, false); selection?.transformBox.update(selected); ctx.onChange(ids); }, disabled: !hasSel }, + { label: 'Flip Horizontal', shortcut: 'Alt+Shift+H', onClick: () => { ops.flipHorizontal(selected); selection?.transformBox.update(selected); ctx.onChange(ids); }, disabled: !hasSel || selected.some(i => ['pdf-page', 'sticky', 'markdown', 'text'].includes(i.data.type)) }, + { label: 'Flip Vertical', shortcut: 'Alt+Shift+V', onClick: () => { ops.flipVertical(selected); selection?.transformBox.update(selected); ctx.onChange(ids); }, disabled: !hasSel || selected.some(i => ['pdf-page', 'sticky', 'markdown', 'text'].includes(i.data.type)) }, + { label: 'Rotate Clockwise', shortcut: 'R', onClick: () => { ops.rotate90(selected, true); selection?.transformBox.update(selected); ctx.onChange(ids); }, disabled: !hasSel || selected.some(i => ['pdf-page', 'sticky', 'markdown', 'text'].includes(i.data.type)) }, + { label: 'Rotate Counter-Clockwise', shortcut: 'Shift+R', onClick: () => { ops.rotate90(selected, false); selection?.transformBox.update(selected); ctx.onChange(ids); }, disabled: !hasSel || selected.some(i => ['pdf-page', 'sticky', 'markdown', 'text'].includes(i.data.type)) }, { label: 'Crop', shortcut: 'C', onClick: () => ctx.startCrop?.(), disabled: selected.length !== 1 || selected[0]?.data.type !== 'image' }, { label: 'Reset Transform', shortcut: 'Ctrl+Shift+T', onClick: () => { ops.resetTransform(selected); selection?.transformBox.update(selected); ctx.onChange(ids); }, disabled: !hasSel }, { label: '', shortcut: '', onClick: () => {}, divider: true }, diff --git a/frontend/src/canvas/shortcut-definitions.ts b/frontend/src/canvas/shortcut-definitions.ts index df9b66b..b2c7a1f 100644 --- a/frontend/src/canvas/shortcut-definitions.ts +++ b/frontend/src/canvas/shortcut-definitions.ts @@ -238,12 +238,20 @@ export const shortcuts: ShortcutDef[] = [ { id: 'flip-h', keys: { key: 'h', alt: true, shift: true }, category: 'image', description: 'Flip horizontal', needsSelection: true, - handler: (ctx) => _opUpdate(ctx, ops.flipHorizontal), + handler: (ctx) => { + const items = ctx.selection.getSelectedItems(); + if (items.some(i => ['pdf-page', 'sticky', 'markdown', 'text'].includes(i.data.type))) return; + _opUpdate(ctx, ops.flipHorizontal); + }, }, { id: 'flip-v', keys: { key: 'v', alt: true, shift: true }, category: 'image', description: 'Flip vertical', needsSelection: true, - handler: (ctx) => _opUpdate(ctx, ops.flipVertical), + handler: (ctx) => { + const items = ctx.selection.getSelectedItems(); + if (items.some(i => ['pdf-page', 'sticky', 'markdown', 'text'].includes(i.data.type))) return; + _opUpdate(ctx, ops.flipVertical); + }, }, { id: 'reset-transform', keys: { key: 't', ctrl: true, shift: true }, @@ -316,12 +324,20 @@ export const shortcuts: ShortcutDef[] = [ { id: 'rotate-cw', keys: { key: 'r' }, category: 'image', description: 'Rotate 90° clockwise', needsSelection: true, - handler: (ctx) => _opUpdate(ctx, (items) => ops.rotate90(items, true)), + handler: (ctx) => { + const items = ctx.selection.getSelectedItems(); + if (items.some(i => ['pdf-page', 'sticky', 'markdown', 'text'].includes(i.data.type))) return; + _opUpdate(ctx, (items) => ops.rotate90(items, true)); + }, }, { id: 'rotate-ccw', keys: { key: 'r', shift: true }, category: 'image', description: 'Rotate 90° counter-clockwise', needsSelection: true, - handler: (ctx) => _opUpdate(ctx, (items) => ops.rotate90(items, false)), + handler: (ctx) => { + const items = ctx.selection.getSelectedItems(); + if (items.some(i => ['pdf-page', 'sticky', 'markdown', 'text'].includes(i.data.type))) return; + _opUpdate(ctx, (items) => ops.rotate90(items, false)); + }, }, // ═══════════════════════════════════════