From a95d8ebc87a50b30a9f2dd8e625a56add505f2b8 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Tue, 26 Nov 2024 02:43:28 +1100 Subject: [PATCH] Fix invalid callback return value preventing canvas redraw (#343) * Fix invalid callback prevents redraw When widget.mouse() is incorrectly implemented (no return value), it evaluates as falsy and prevents canvas redraw. Changes default behaviour to ignore the return value when nullish. * Fix pointermove for custom widget outside nodes Events are now also sent when the pointer moves outside the bounds of the node. --- src/LGraphCanvas.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 2b8e66d0ed..6418ec5bcb 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -2804,6 +2804,18 @@ export class LGraphCanvas { e.dragging = this.last_mouse_dragging + if (this.node_widget) { + // Legacy widget mouse callbacks for pointermove events + const [node, widget] = this.node_widget + + if (widget?.mouse) { + const x = e.canvasX - node.pos[0] + const y = e.canvasY - node.pos[1] + const result = widget.mouse(e, [x, y], node) + if (result != null) this.dirty_canvas = result + } + } + /** See {@link state}.{@link LGraphCanvasState.hoveringOver hoveringOver} */ let underPointer = CanvasItem.Nothing // get node over @@ -2956,15 +2968,6 @@ export class LGraphCanvas { // Resize corner if (node.inResizeCorner(e.canvasX, e.canvasY)) { underPointer |= CanvasItem.ResizeSe - } else if (this.node_widget) { - // Legacy widget mouse callbacks for pointermove events - const widget = this.node_widget[1] - - if (widget?.mouse) { - const x = e.canvasX - node.pos[0] - const y = e.canvasY - node.pos[1] - this.dirty_canvas = widget.mouse(e, [x, y], node) - } } } else { // Not over a node