Skip to content

Commit

Permalink
pan canvas on wheel button drag (excalidraw#375)
Browse files Browse the repository at this point in the history
* pan canvas on wheel button drag

* make mousemove passive
  • Loading branch information
dwelle authored and vjeux committed Jan 15, 2020
1 parent 80cee4d commit 0e56cd4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,34 @@ export class App extends React.Component<{}, AppState> {
// being in a weird state, we clean up on the next mousedown
lastMouseUp(e);
}

// pan canvas on wheel button drag
if (e.button === 1) {
let { clientX: lastX, clientY: lastY } = e;
const onMouseMove = (e: MouseEvent) => {
document.documentElement.style.cursor = `grabbing`;
let deltaX = lastX - e.clientX;
let deltaY = lastY - e.clientY;
lastX = e.clientX;
lastY = e.clientY;
this.setState(state => ({
scrollX: state.scrollX - deltaX,
scrollY: state.scrollY - deltaY
}));
};
const onMouseUp = (lastMouseUp = (e: MouseEvent) => {
lastMouseUp = null;
resetCursor();
window.removeEventListener("mousemove", onMouseMove);
window.removeEventListener("mouseup", onMouseUp);
});
window.addEventListener("mousemove", onMouseMove, {
passive: true
});
window.addEventListener("mouseup", onMouseUp);
return;
}

// only handle left mouse button
if (e.button !== 0) return;
// fixes mousemove causing selection of UI texts #32
Expand Down

0 comments on commit 0e56cd4

Please sign in to comment.