Add alt-right-click to delete reroutes (#899)

Alt-right-click to remove, regular right-click to show context menu.
This commit is contained in:
filtered
2025-04-07 00:55:17 +10:00
committed by GitHub
parent 6cafeeff19
commit 3b5cc8cd19
2 changed files with 20 additions and 3 deletions

View File

@@ -1324,6 +1324,8 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
}
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)
}

View File

@@ -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<Positionable>) => 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]