Skip to content

Commit 7ed2160

Browse files
committed
feat: add scroll & shift+scroll
1 parent b08e44c commit 7ed2160

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/components/KeyboardShortcutsHelp.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const SHORTCUT_GROUPS: { title: string; shortcuts: Shortcut[] }[] = [
3333
{ keys: ['+'], altKeys: ['='], description: 'Zoom in' },
3434
{ keys: ['-'], description: 'Zoom out' },
3535
{ keys: ['0'], description: 'Fit to view' },
36+
{ keys: ['Scroll'], description: 'Scroll vertically' },
37+
{ keys: ['Shift + Scroll'], description: 'Scroll horizontally' },
3638
{ keys: ['Ctrl/Cmd + Scroll'], description: 'Zoom to cursor' },
3739
{ keys: ['Space + Drag'], description: 'Pan' },
3840
{ keys: ['Middle Click + Drag'], description: 'Pan' },

src/hooks/useCanvasInteraction.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,24 @@ export function useCanvasInteraction(
6969
const canvas = canvasRef.current;
7070
if (!canvas) return;
7171

72-
// --- Ctrl+Wheel zoom ---
72+
// --- Wheel: zoom / scroll ---
7373
const onWheel = (e: WheelEvent) => {
74-
if (!e.ctrlKey && !e.metaKey) return;
75-
e.preventDefault();
76-
const { zoom } = useAppStore.getState();
77-
const delta = e.deltaY < 0 ? ZOOM_STEP : -ZOOM_STEP;
78-
applyZoom(zoom + delta, e.offsetX, e.offsetY);
74+
e.stopPropagation();
75+
const { zoom, panX, panY } = useAppStore.getState();
76+
77+
if (e.ctrlKey || e.metaKey) {
78+
// Zoom toward cursor — must prevent browser zoom
79+
e.preventDefault();
80+
const delta = e.deltaY < 0 ? ZOOM_STEP : -ZOOM_STEP;
81+
applyZoom(zoom + delta, e.offsetX, e.offsetY);
82+
} else if (e.shiftKey) {
83+
// Horizontal pan
84+
const d = e.deltaX || e.deltaY;
85+
useAppStore.getState().setViewport(zoom, panX - d, panY);
86+
} else {
87+
// Vertical pan
88+
useAppStore.getState().setViewport(zoom, panX, panY - e.deltaY);
89+
}
7990
};
8091

8192
// --- Pointer down: pan, select, or start drawing ---

0 commit comments

Comments
 (0)