Skip to content

Commit

Permalink
Fix: zoom gestures
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Apr 12, 2024
1 parent 99ff3b6 commit 5962577
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/components/workspace/zoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,16 @@ const Zoom = (props: Pick<ISTKProps, "mode" | "styles" | "options">) => {
if (selectedTool == Tool.Pan) {
selection.call(zoom);
} else {
selection
.call(zoom)
.on("mousedown.zoom", null)
.on("touchstart.zoom", null)
.on("touchmove.zoom", null)
.on("touchend.zoom", null)
.on("wheel.zoom", (e) => {
e.preventDefault();
const currentZoom = selection.property("__zoom").k || 1;
if (e.ctrlKey) {
const nextZoom = currentZoom * Math.pow(2, -e.deltaY * 0.01);
zoom.scaleTo(selection, nextZoom, d3Extended.pointer(e));
} else {
zoom.translateBy(selection, -(e.deltaX / currentZoom), -(e.deltaY / currentZoom));
}
});
selection.call(zoom).on("wheel.zoom", (e) => {
e.preventDefault();
const currentZoom = selection.property("__zoom").k || 1;
if (e.ctrlKey) {
const nextZoom = currentZoom * Math.pow(2, -e.deltaY * 0.01);
zoom.scaleTo(selection, nextZoom, d3Extended.pointer(e));
} else {
zoom.translateBy(selection, -(e.deltaX / currentZoom), -(e.deltaY / currentZoom));
}
});
}
}, [selectedTool]);

Expand Down

0 comments on commit 5962577

Please sign in to comment.