From 0daacfd914c1c9160af093f5edb2c93755d3972c Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 18 Aug 2025 10:10:38 -0700 Subject: [PATCH] [fix] Restore ability to override onMouseDown in node subclasses (#5079) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a regression where node subclasses could no longer override the onMouseDown method. The issue was introduced when title button support was added by assigning onMouseDown in the constructor, which prevented proper method inheritance. Changes: - Remove onMouseDown assignment from LGraphNode constructor - Move title button click detection to LGraphCanvas before calling node.onMouseDown - This preserves title button functionality while allowing subclasses to override onMouseDown Fixes #5073 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude --- src/lib/litegraph/src/LGraphCanvas.ts | 20 +++++++++++++++++++ src/lib/litegraph/src/LGraphNode.ts | 28 --------------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/lib/litegraph/src/LGraphCanvas.ts b/src/lib/litegraph/src/LGraphCanvas.ts index ac0a9b8ed2..83a8cdcd53 100644 --- a/src/lib/litegraph/src/LGraphCanvas.ts +++ b/src/lib/litegraph/src/LGraphCanvas.ts @@ -2683,6 +2683,26 @@ export class LGraphCanvas this.processNodeDblClicked(node) } + // Check for title button clicks before calling onMouseDown + if (node.title_buttons?.length && !node.flags.collapsed) { + // pos contains the offset from the node's position, so we need to use node-relative coordinates + const nodeRelativeX = pos[0] + const nodeRelativeY = pos[1] + + for (let i = 0; i < node.title_buttons.length; i++) { + const button = node.title_buttons[i] + if ( + button.visible && + button.isPointInside(nodeRelativeX, nodeRelativeY) + ) { + node.onTitleButtonClick(button, this) + // Set a no-op click handler to prevent fallback canvas dragging + pointer.onClick = () => {} + return + } + } + } + // Mousedown callback - can block drag if (node.onMouseDown?.(e, pos, this)) { // Node handled the event (e.g., title button clicked) diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index 6d8b202b48..34e8b94324 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -728,34 +728,6 @@ export class LGraphNode error: this.#getErrorStrokeStyle, selected: this.#getSelectedStrokeStyle } - - // Assign onMouseDown implementation - this.onMouseDown = ( - // @ts-expect-error - CanvasPointerEvent type needs fixing - e: CanvasPointerEvent, - pos: Point, - canvas: LGraphCanvas - ): boolean => { - // Check for title button clicks (only if not collapsed) - if (this.title_buttons?.length && !this.flags.collapsed) { - // pos contains the offset from the node's position, so we need to use node-relative coordinates - const nodeRelativeX = pos[0] - const nodeRelativeY = pos[1] - - for (let i = 0; i < this.title_buttons.length; i++) { - const button = this.title_buttons[i] - if ( - button.visible && - button.isPointInside(nodeRelativeX, nodeRelativeY) - ) { - this.onTitleButtonClick(button, canvas) - return true // Prevent default behavior - } - } - } - - return false // Allow default behavior - } } /** Internal callback for subgraph nodes. Do not implement externally. */