Skip to content

Commit 9f535f0

Browse files
committed
Fix: added two finger panning
1 parent 886e362 commit 9f535f0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/components/workspace/zoom.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,22 @@ const Zoom = () => {
5151
if (selectedTool == Tool.Pan) {
5252
d3.select(`#${ids.workspace}`).call(zoom);
5353
} else {
54-
d3.select(`#${ids.workspace}`)
54+
selection
5555
.call(zoom)
5656
.on("mousedown.zoom", null)
5757
.on("touchstart.zoom", null)
5858
.on("touchmove.zoom", null)
59-
.on("touchend.zoom", null);
59+
.on("touchend.zoom", null)
60+
.on("wheel.zoom", (e) => {
61+
e.preventDefault();
62+
const currentZoom = selection.property("__zoom").k || 1;
63+
if (e.ctrlKey) {
64+
const nextZoom = currentZoom * Math.pow(2, -e.deltaY * 0.01);
65+
zoom.scaleTo(selection, nextZoom, d3.pointer(e));
66+
} else {
67+
zoom.translateBy(selection, -(e.deltaX / currentZoom), -(e.deltaY / currentZoom));
68+
}
69+
});
6070
}
6171
}, [selectedTool]);
6272

0 commit comments

Comments
 (0)