Remove DragAndScale rounding when using trackpad (#1009)

Fixes issue where pinch to zoom would jitter around scale 1 - D&S rounds
the value to exactly 1 when it is "close enough". Good for pointer, poor
UX for precision trackpad.
This commit is contained in:
filtered
2025-05-05 07:06:43 +10:00
committed by GitHub
parent 53f766af3d
commit 386f18a1e5
2 changed files with 10 additions and 8 deletions

View File

@@ -122,7 +122,7 @@ export class DragAndScale {
this.onredraw?.(this)
}
changeScale(value: number, zooming_center?: Point): void {
changeScale(value: number, zooming_center?: Point, roundToScaleOne = true): void {
if (value < this.min_scale) {
value = this.min_scale
} else if (value > this.max_scale) {
@@ -143,7 +143,7 @@ export class DragAndScale {
]
const center = this.convertCanvasToOffset(normalizedCenter)
this.scale = value
if (Math.abs(this.scale - 1) < 0.01) this.scale = 1
if (roundToScaleOne && Math.abs(this.scale - 1) < 0.01) this.scale = 1
const new_center = this.convertCanvasToOffset(normalizedCenter)
const delta_offset = [
new_center[0] - center[0],

View File

@@ -2974,18 +2974,20 @@ export class LGraphCanvas {
) {
if (e.ctrlKey && !Number.isInteger(e.deltaY)) {
scale *= 1 + e.deltaY * (1 - this.zoom_speed) * 0.18
this.ds.changeScale(scale, [e.clientX, e.clientY], false)
} else {
this.ds.offset[0] -= e.deltaX * 1.18 * (1 / scale)
this.ds.offset[1] -= e.deltaY * 1.18 * (1 / scale)
}
} else if (delta > 0) {
scale *= this.zoom_speed
} else if (delta < 0) {
scale *= 1 / (this.zoom_speed)
} else {
if (delta > 0) {
scale *= this.zoom_speed
} else if (delta < 0) {
scale *= 1 / (this.zoom_speed)
}
this.ds.changeScale(scale, [e.clientX, e.clientY])
}
this.ds.changeScale(scale, [e.clientX, e.clientY])
this.graph.change()
e.preventDefault()