Backspace delete selected (Nodes + Groups) (#265)

* Backspace delete selected (Nodes + Groups)

* nit

* nit
This commit is contained in:
Chenlei Hu
2024-11-03 17:22:08 -05:00
committed by GitHub
parent 62bc1ecd9f
commit 6180f5ef55
2 changed files with 56 additions and 20 deletions

View File

@@ -2373,4 +2373,32 @@ export class LGraphNode implements Positionable {
currentX += badge.getWidth(ctx) + gap
}
}
/**
* Try auto-connect input to output without this node when possible
* (very basic, only takes into account first input-output)
*
* @returns true if connected, false otherwise
*/
connectInputToOutput(): boolean {
if (
this.inputs?.length &&
this.outputs &&
this.outputs.length &&
LiteGraph.isValidConnection(this.inputs[0].type, this.outputs[0].type) &&
this.inputs[0].link &&
this.outputs[0].links &&
this.outputs[0].links.length
) {
const input_link = this.graph._links.get(this.inputs[0].link)
const output_link = this.graph._links.get(this.outputs[0].links[0])
const input_node = this.getInputNode(0)
const output_node = this.getOutputNodes(0)[0]
if (input_node && output_node) {
input_node.connect(input_link.origin_slot, output_node, output_link.target_slot)
return true
}
}
return false
}
}