From 3b5cc8cd19d918f2f0bc897a7a862680cd77bb8e Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Mon, 7 Apr 2025 00:55:17 +1000 Subject: [PATCH] Add alt-right-click to delete reroutes (#899) Alt-right-click to remove, regular right-click to show context menu. --- src/LGraph.ts | 2 ++ src/LGraphCanvas.ts | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/LGraph.ts b/src/LGraph.ts index 5bfc67d61..b39fdc7de 100644 --- a/src/LGraph.ts +++ b/src/LGraph.ts @@ -1324,6 +1324,8 @@ export class LGraph implements LinkNetwork, Serialisable { } reroutes.delete(id) + // This does not belong here; it should be handled by the caller, or run by a remove-many API. + // https://github.com/Comfy-Org/litegraph.js/issues/898 this.setDirtyCanvas(false, true) } diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 4f1810cd2..3228e3aec 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -555,7 +555,7 @@ export class LGraphCanvas implements ConnectionColorContext { onClear?: () => void /** called after moving a node @deprecated Does not handle multi-node move, and can return the wrong node. */ onNodeMoved?: (node_dragged: LGraphNode | undefined) => void - /** called if the selection changes */ + /** @deprecated Called with the deprecated {@link selected_nodes} when the selection changes. Replacement not yet impl. */ onSelectionChange?: (selected: Dictionary) => void /** called when rendering a tooltip */ onDrawLinkTooltip?: ( @@ -1882,11 +1882,26 @@ export class LGraphCanvas implements ConnectionColorContext { } else if (this.links_render_mode !== LinkRenderType.HIDDEN_LINK) { // Reroutes const reroute = graph.getRerouteOnPos(e.canvasX, e.canvasY) - if (reroute) this.processSelect(reroute, e, true) + if (reroute) { + if (e.altKey) { + pointer.onClick = (upEvent) => { + if (upEvent.altKey) { + // Ensure deselected + if (reroute.selected) { + this.deselect(reroute) + this.onSelectionChange?.(this.selected_nodes) + } + reroute.remove() + } + } + } else { + this.processSelect(reroute, e, true) + } + } } // Show context menu for the node or group under the pointer - pointer.onClick = () => this.processContextMenu(node, e) + pointer.onClick ??= () => this.processContextMenu(node, e) } this.last_mouse = [x, y]