Skip to content

Commit 0daacfd

Browse files
[fix] Restore ability to override onMouseDown in node subclasses (#5079)
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 <[email protected]>
1 parent 5a35562 commit 0daacfd

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

src/lib/litegraph/src/LGraphCanvas.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,26 @@ export class LGraphCanvas
26832683
this.processNodeDblClicked(node)
26842684
}
26852685

2686+
// Check for title button clicks before calling onMouseDown
2687+
if (node.title_buttons?.length && !node.flags.collapsed) {
2688+
// pos contains the offset from the node's position, so we need to use node-relative coordinates
2689+
const nodeRelativeX = pos[0]
2690+
const nodeRelativeY = pos[1]
2691+
2692+
for (let i = 0; i < node.title_buttons.length; i++) {
2693+
const button = node.title_buttons[i]
2694+
if (
2695+
button.visible &&
2696+
button.isPointInside(nodeRelativeX, nodeRelativeY)
2697+
) {
2698+
node.onTitleButtonClick(button, this)
2699+
// Set a no-op click handler to prevent fallback canvas dragging
2700+
pointer.onClick = () => {}
2701+
return
2702+
}
2703+
}
2704+
}
2705+
26862706
// Mousedown callback - can block drag
26872707
if (node.onMouseDown?.(e, pos, this)) {
26882708
// Node handled the event (e.g., title button clicked)

src/lib/litegraph/src/LGraphNode.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -728,34 +728,6 @@ export class LGraphNode
728728
error: this.#getErrorStrokeStyle,
729729
selected: this.#getSelectedStrokeStyle
730730
}
731-
732-
// Assign onMouseDown implementation
733-
this.onMouseDown = (
734-
// @ts-expect-error - CanvasPointerEvent type needs fixing
735-
e: CanvasPointerEvent,
736-
pos: Point,
737-
canvas: LGraphCanvas
738-
): boolean => {
739-
// Check for title button clicks (only if not collapsed)
740-
if (this.title_buttons?.length && !this.flags.collapsed) {
741-
// pos contains the offset from the node's position, so we need to use node-relative coordinates
742-
const nodeRelativeX = pos[0]
743-
const nodeRelativeY = pos[1]
744-
745-
for (let i = 0; i < this.title_buttons.length; i++) {
746-
const button = this.title_buttons[i]
747-
if (
748-
button.visible &&
749-
button.isPointInside(nodeRelativeX, nodeRelativeY)
750-
) {
751-
this.onTitleButtonClick(button, canvas)
752-
return true // Prevent default behavior
753-
}
754-
}
755-
}
756-
757-
return false // Allow default behavior
758-
}
759731
}
760732

761733
/** Internal callback for subgraph nodes. Do not implement externally. */

0 commit comments

Comments
 (0)