diff --git a/src/widgets/BaseWidget.ts b/src/widgets/BaseWidget.ts index 638b88d15f..2ca7b94013 100644 --- a/src/widgets/BaseWidget.ts +++ b/src/widgets/BaseWidget.ts @@ -113,6 +113,7 @@ export abstract class BaseWidget implements IBaseWidget { }) { const { node, canvas, e } = options const oldValue = this.value + if (value === this.value) return const v = this.type === "number" ? Number(value) : value this.value = v diff --git a/src/widgets/NumberWidget.ts b/src/widgets/NumberWidget.ts index 1aa648efcb..8622fbc670 100644 --- a/src/widgets/NumberWidget.ts +++ b/src/widgets/NumberWidget.ts @@ -19,6 +19,21 @@ export class NumberWidget extends BaseWidget implements INumericWidget { this.value = widget.value } + override setValue(value: number, options: { + e: CanvasMouseEvent + node: LGraphNode + canvas: LGraphCanvas + }) { + let newValue = value + if (this.options.min != null && newValue < this.options.min) { + newValue = this.options.min + } + if (this.options.max != null && newValue > this.options.max) { + newValue = this.options.max + } + super.setValue(newValue, options) + } + /** * Draws the widget * @param ctx The canvas context @@ -111,16 +126,7 @@ export class NumberWidget extends BaseWidget implements INumericWidget { if (delta) { // Handle left/right arrow clicks - let newValue = this.value + delta * getWidgetStep(this.options) - if (this.options.min != null && newValue < this.options.min) { - newValue = this.options.min - } - if (this.options.max != null && newValue > this.options.max) { - newValue = this.options.max - } - if (newValue !== this.value) { - this.setValue(newValue, { e, node, canvas }) - } + this.setValue(this.value + delta * getWidgetStep(this.options), { e, node, canvas }) return } @@ -159,18 +165,6 @@ export class NumberWidget extends BaseWidget implements INumericWidget { : 0) if (delta && (x > -3 && x < width + 3)) return - - let newValue = this.value - if (e.deltaX) newValue += e.deltaX * getWidgetStep(this.options) - - if (this.options.min != null && newValue < this.options.min) { - newValue = this.options.min - } - if (this.options.max != null && newValue > this.options.max) { - newValue = this.options.max - } - if (newValue !== this.value) { - this.setValue(newValue, { e, node, canvas }) - } + this.setValue(this.value + (e.deltaX ?? 0) * getWidgetStep(this.options), { e, node, canvas }) } }