Skip to content

Commit

Permalink
Merge pull request #340 from yojeek/2.0-fix-copy-paste-incorrect-nodeid
Browse files Browse the repository at this point in the history
Fix old nodeId assigned to copied node's interfaces
  • Loading branch information
newcat authored Nov 21, 2023
2 parents 5d00311 + 967e850 commit 09da434
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/renderer-vue/src/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ export function useClipboard(

commandHandler.executeCommand<StartTransactionCommand>(START_TRANSACTION_COMMAND);

for (const n of parsedNodeBuffer) {
const nodeType = editor.value.nodeTypes.get(n.type);
for (const oldNode of parsedNodeBuffer) {
const nodeType = editor.value.nodeTypes.get(oldNode.type);
if (!nodeType) {
console.warn(`Node type ${n.type} not registered`);
console.warn(`Node type ${oldNode.type} not registered`);
return;
}
const copiedNode = new nodeType.type();
Expand All @@ -121,17 +121,17 @@ export function useClipboard(
copiedNode.hooks.beforeLoad.subscribe(token, (nodeState) => {
const ns = nodeState as any;
if (ns.position) {
ns.position.x += 10;
ns.position.y += 10;
ns.position.x += 100;
ns.position.y += 100;
}
copiedNode.hooks.beforeLoad.unsubscribe(token);
return ns;
});

graph.addNode(copiedNode);
copiedNode.load(n);
copiedNode.load({ ...oldNode, id: generatedId });
copiedNode.id = generatedId;
idmap.set(n.id, generatedId);
idmap.set(oldNode.id, generatedId);
}

for (const c of parsedConnectionBuffer) {
Expand Down

0 comments on commit 09da434

Please sign in to comment.