From 386f18a1e50b9e476c7fb03314eb2cfe68f720ca Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Mon, 5 May 2025 07:06:43 +1000 Subject: [PATCH] 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. --- src/DragAndScale.ts | 4 ++-- src/LGraphCanvas.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/DragAndScale.ts b/src/DragAndScale.ts index 02516abd8..b95b24e5a 100644 --- a/src/DragAndScale.ts +++ b/src/DragAndScale.ts @@ -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], diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 7e1fbb9f4..13e04b353 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -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()