Scroll wheel fixes & enhancements (#501)
* scroll wheel fixes & enhancements 1. correct zoom direction (was reversed) 2. support ctrl+scroll for zoom (in addition to alt+scroll) 3. support shift+scroll for horizontal pan * Allow two-axis panning Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
This commit is contained in:
parent
36a6026cb3
commit
372cc690c7
1 changed files with 12 additions and 4 deletions
|
@ -28,17 +28,25 @@ export function useZoomEvents<T extends HTMLElement>(zoom: number, ref: React.Re
|
|||
}, [])
|
||||
|
||||
const handleWheel = React.useCallback<Handler<'wheel', WheelEvent>>(
|
||||
({ delta, event: e }) => {
|
||||
({ delta: wheelDelta, event: e }) => {
|
||||
e.preventDefault()
|
||||
if (e.altKey && e.buttons === 0) {
|
||||
// alt+scroll or ctrl+scroll = zoom
|
||||
if ((e.altKey || e.ctrlKey) && e.buttons === 0) {
|
||||
const point = inputs.pointer?.point ?? [bounds.width / 2, bounds.height / 2]
|
||||
const info = inputs.pinch(point, point)
|
||||
callbacks.onZoom?.({ ...info, delta: [...point, -e.deltaY] }, e)
|
||||
const delta = [...point, wheelDelta[1]]
|
||||
callbacks.onZoom?.({ ...info, delta }, e)
|
||||
return
|
||||
}
|
||||
// otherwise pan
|
||||
const delta = e.shiftKey
|
||||
? // shift+scroll = pan horizontally
|
||||
[wheelDelta[1], 0]
|
||||
: // scroll = pan vertically (or in any direction on a trackpad)
|
||||
[...wheelDelta]
|
||||
if (inputs.isPinching) return
|
||||
if (Vec.isEqual(delta, [0, 0])) return
|
||||
const info = inputs.pan(delta, e as WheelEvent)
|
||||
const info = inputs.pan(delta, e)
|
||||
callbacks.onPan?.(info, e)
|
||||
},
|
||||
[callbacks, inputs, bounds]
|
||||
|
|
Loading…
Reference in a new issue