fix scroll event coords (#2180)

Follow up to #2149 to make sure it works when tldraw is not mounted at
0,0 in document space. Try it out in the 'multiple' examples

### Change Type

- [x] `patch` — Bug fix
This commit is contained in:
David Sheldrick 2023-11-08 14:34:26 +00:00 committed by GitHub
parent 0e39c31c6e
commit ba4664d279
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -115,11 +115,16 @@ export function useGestureEvents(ref: React.RefObject<HTMLDivElement>) {
if (delta.x === 0 && delta.y === 0) return if (delta.x === 0 && delta.y === 0) return
const container = editor.getContainer().getBoundingClientRect()
const info: TLWheelEventInfo = { const info: TLWheelEventInfo = {
type: 'wheel', type: 'wheel',
name: 'wheel', name: 'wheel',
delta, delta,
point: new Vec2d(event.x, event.y), point: new Vec2d(event.clientX, event.clientY).sub({
x: container.left,
y: container.top,
}),
shiftKey: event.shiftKey, shiftKey: event.shiftKey,
altKey: event.altKey, altKey: event.altKey,
ctrlKey: event.metaKey || event.ctrlKey, ctrlKey: event.metaKey || event.ctrlKey,