fix(ui): copied edges must have new ids set

Problems this was causing:
- Deleting an edge was a copy of another edge deletes both edges
- Deleting a node that was a copy-with-edges of another node deletes its edges and it's original edges, leaving what I will call "ghost noodles" behind
This commit is contained in:
psychedelicious 2024-07-25 19:19:03 +10:00
parent ba747373db
commit bb876b8d4e

View File

@ -59,17 +59,19 @@ const pasteSelection = (withEdgesToCopiedNodes?: boolean) => {
for (const edge of copiedEdges) { for (const edge of copiedEdges) {
if (edge.source === node.id) { if (edge.source === node.id) {
edge.source = id; edge.source = id;
edge.id = edge.id.replace(node.data.id, id); } else if (edge.target === node.id) {
}
if (edge.target === node.id) {
edge.target = id; edge.target = id;
edge.id = edge.id.replace(node.data.id, id);
} }
} }
node.id = id; node.id = id;
node.data.id = id; node.data.id = id;
}); });
copiedEdges.forEach((edge) => {
// Copied edges need a fresh id too
edge.id = uuidv4();
});
const nodeChanges: NodeChange[] = []; const nodeChanges: NodeChange[] = [];
const edgeChanges: EdgeChange[] = []; const edgeChanges: EdgeChange[] = [];
// Deselect existing nodes // Deselect existing nodes