Skip to content

Commit a7cbf1b

Browse files
Deep copy subgraphs to clipboard, update nested ids on paste (#5003) (#5022)
* Deep copy to clipboard, update nested ids on paste The copyToClipboard function wasn't walking subgraphs and leaving nested subgraphs unserialized. This has now been fixed. This requires that equivalent support be added to _pasteFromClipboard to update the ids of nested subgraphs which are pasted. * Add extra advisory comments Co-authored-by: AustinMroz <[email protected]>
1 parent 30009e2 commit a7cbf1b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/lib/litegraph/src/LGraphCanvas.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,6 +3607,7 @@ export class LGraphCanvas
36073607
subgraphs: []
36083608
}
36093609

3610+
// NOTE: logic for traversing nested subgraphs depends on this being a set.
36103611
const subgraphs = new Set<Subgraph>()
36113612

36123613
// Create serialisable objects
@@ -3645,8 +3646,13 @@ export class LGraphCanvas
36453646
}
36463647

36473648
// Add unique subgraph entries
3648-
// TODO: Must find all nested subgraphs
3649+
// NOTE: subgraphs is appended to mid iteration.
36493650
for (const subgraph of subgraphs) {
3651+
for (const node of subgraph.nodes) {
3652+
if (node instanceof SubgraphNode) {
3653+
subgraphs.add(node.subgraph)
3654+
}
3655+
}
36503656
const cloned = subgraph.clone(true).asSerialisable()
36513657
serialisable.subgraphs.push(cloned)
36523658
}
@@ -3763,12 +3769,19 @@ export class LGraphCanvas
37633769
created.push(group)
37643770
}
37653771

3772+
// Update subgraph ids with nesting
3773+
function updateSubgraphIds(nodes: { type: string }[]) {
3774+
for (const info of nodes) {
3775+
const subgraph = results.subgraphs.get(info.type)
3776+
if (!subgraph) continue
3777+
info.type = subgraph.id
3778+
updateSubgraphIds(subgraph.nodes)
3779+
}
3780+
}
3781+
updateSubgraphIds(parsed.nodes)
3782+
37663783
// Nodes
37673784
for (const info of parsed.nodes) {
3768-
// If the subgraph was cloned, update references to use the new subgraph ID.
3769-
const subgraph = results.subgraphs.get(info.type)
3770-
if (subgraph) info.type = subgraph.id
3771-
37723785
const node = info.type == null ? null : LiteGraph.createNode(info.type)
37733786
if (!node) {
37743787
// failedNodes.push(info)

0 commit comments

Comments
 (0)