Skip to content

fix(canvas): read deltaX so shift + wheel scrolls horizontally in Chrome - #1133

Open
ntdatt812 wants to merge 1 commit into
drawdb-io:mainfrom
ntdatt812:fix/1108-shift-wheel-horizontal-scroll
Open

ntdatt812 wants to merge 1 commit into
drawdb-io:mainfrom
ntdatt812:fix/1108-shift-wheel-horizontal-scroll

Conversation

@ntdatt812

@ntdatt812 ntdatt812 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1108.

Why nothing moved

The wheel handler's shift branch pans by e.deltaY:

} else if (e.shiftKey) {
  ... x: prev.pan.x + e.deltaY / prev.zoom

But Chrome does the shift translation itself: with Shift held it reports the scroll on deltaX and leaves deltaY at 0. So the branch was entered and then added zero, which is exactly the reported symptom — the diagram does not move, rather than moving the wrong way. Firefox keeps the value on deltaY with shiftKey set, which is why this looks browser-specific.

Both are now read: deltaX when it carries the scroll, deltaY otherwise.

A second case it picks up

The condition also admits e.deltaX !== 0 without a modifier. A trackpad's two-finger horizontal gesture and a tilt wheel send exactly that, and they used to fall through to the final else, which pans vertically by deltaY — also 0 on a purely horizontal event. So those did nothing either, for the same reason. It is the same defect through a different door, so I fixed it in the same condition rather than leaving a dead path next to the one being fixed. Happy to split it out if you would rather keep the PR to the reported case.

Vertical scrolling and ctrl/cmd zoom are untouched.

Verification

npx eslint src/components/EditorCanvas/Canvas.jsx → No issues found. The repo has no test runner (dev, build, lint, preview only), so there is nothing to add a regression test to.

I have not run the app to confirm the behaviour, and I would rather say so than present results I did not observe. The reasoning is from the handler and the WheelEvent contract: Chrome sets deltaX and zeroes deltaY for shift + wheel, which makes the existing branch an addition of zero — and that matches the reported symptom exactly.

What a reviewer should see on the canvas:

input expected after
Shift + wheel, Chrome pans horizontally (was: nothing)
Shift + wheel, Firefox pans horizontally (unchanged)
trackpad horizontal swipe pans horizontally (was: nothing)
wheel, no modifier pans vertically (unchanged)
ctrl/cmd + wheel zooms (unchanged)

The shift branch panned by e.deltaY, but Chrome translates shift + wheel into
deltaX and reports deltaY as 0. Adding 0 to pan.x meant the diagram did not
move at all. Firefox keeps the value on deltaY with shiftKey set, so both have
to be read.

Taking deltaX whenever it is non-zero also makes a trackpad's horizontal
gesture and a tilt wheel pan the canvas, which send deltaX with no modifier
and previously fell through to the vertical branch, where deltaY is 0 — so
those did nothing either.

Refs drawdb-io#1108.
@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

@ntdatt812 is attempting to deploy a commit to the dottle's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Mouse Wheel Horizontal Scroll not working

1 participant