Compare commits

...

2 Commits

Author SHA1 Message Date
Terry Jia
660ea502ae remove the pan for the horizontal gesture 2025-09-12 15:40:27 -04:00
Terry Jia
551c698e7f allow zoom canvas by mouse wheel scroll without ctrl 2025-09-11 21:20:14 -04:00

View File

@@ -3623,14 +3623,17 @@ export class LGraphCanvas
let { scale } = this.ds
// Detect if this is a trackpad gesture or mouse wheel
// Detect if this is a trackpad gesture or mouse wheel (but not accurate on some cases)
const isTrackpad = this.pointer.isTrackpadGesture(e)
const isCtrlOrMacMeta =
e.ctrlKey || (e.metaKey && navigator.platform.includes('Mac'))
const isZoomModifier = isCtrlOrMacMeta && !e.altKey && !e.shiftKey
if (isZoomModifier || LiteGraph.canvasNavigationMode === 'legacy') {
// Legacy mode or standard mode with ctrl - use wheel for zoom
// remove isCtrlOrMacMeta to allow zoom with wheel scroll directly without ctrl
const isZoomModifier = !e.altKey && !e.shiftKey
// unify the logic of mouse wheel and trackpad pan vertically, because we could not detect the trackpad or mouse wheel when user pan vertically with trackpad
if (
(e.deltaX === 0 && e.deltaY !== 0 && isZoomModifier) ||
LiteGraph.canvasNavigationMode === 'legacy'
) {
if (isTrackpad) {
// Trackpad gesture - use smooth scaling
scale *= 1 + e.deltaY * (1 - this.zoom_speed) * 0.18
@@ -3645,14 +3648,13 @@ export class LGraphCanvas
this.ds.changeScale(scale, [e.clientX, e.clientY])
}
} else {
// Standard mode without ctrl - use wheel / gestures to pan
// Standard mode - use wheel / gestures to pan
// Trackpads and mice work on significantly different scales
const factor = isTrackpad ? 0.18 : 0.008_333
if (!isTrackpad && e.shiftKey && e.deltaX === 0) {
this.ds.offset[0] -= e.deltaY * (1 + factor) * (1 / scale)
} else {
this.ds.offset[0] -= e.deltaX * (1 + factor) * (1 / scale)
this.ds.offset[1] -= e.deltaY * (1 + factor) * (1 / scale)
}
}