Skip to content

Commit af7cefc

Browse files
adamgerhantKeavon
authored andcommitted
Fix deletion
1 parent 7f10a42 commit af7cefc

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4605,37 +4605,33 @@ impl NodeNetworkInterface {
46054605
continue;
46064606
};
46074607

4608+
// Perform an upstream traversal to try delete children
46084609
for upstream_id in self.upstream_flow_back_from_nodes(vec![*node_id], network_path, FlowType::LayerChildrenUpstreamFlow) {
4609-
// This does a downstream traversal starting from the current node, and ending at either a node in the `delete_nodes` set or the output.
4610-
// If the traversal find as child node of a node in the `delete_nodes` set, then it is a sole dependent. If the output node is eventually reached, then it is not a sole dependent.
4610+
// For each potential child perform a complete downstream traveral, ending at either a node in the `delete_nodes` set, the output, or a dead end.
4611+
// If the output node is eventually reached, then it is not a sole dependent and will not be deleted
46114612
let mut stack = vec![OutputConnector::node(upstream_id, 0)];
46124613
let mut can_delete = true;
46134614
while let Some(current_node) = stack.pop() {
46144615
let current_node_id = current_node.node_id().expect("The current node in the delete stack cannot be the export");
46154616
let Some(downstream_nodes) = outward_wires.get(&current_node) else { continue };
4617+
// If there are no outward wires, then we have reached a dead end, and the node cannot be deleted
4618+
if downstream_nodes.is_empty() {
4619+
can_delete = false;
4620+
break;
4621+
}
46164622
for downstream_node in downstream_nodes {
46174623
if let InputConnector::Node { node_id: downstream_id, .. } = downstream_node {
4624+
// If the downstream node is not in the delete nodes set, then continue iterating
46184625
if !delete_nodes.contains(downstream_id) {
4619-
can_delete = false;
4620-
break;
4621-
}
4622-
// Continue traversing over the downstream sibling, if the current node is a sibling to a node that will be deleted and it is a layer
4623-
else {
4624-
for deleted_node_id in &nodes_to_delete {
4625-
let Some(downstream_node) = self.document_node(deleted_node_id, network_path) else { continue };
4626-
let Some(input) = downstream_node.inputs.first() else { continue };
4627-
4628-
if let NodeInput::Node { node_id, .. } = input {
4629-
if *node_id == current_node_id {
4630-
stack.push(OutputConnector::node(*deleted_node_id, 0));
4631-
}
4632-
}
4626+
for output_index in 0..self.number_of_outputs(downstream_id, network_path) {
4627+
stack.push(OutputConnector::node(*downstream_id, output_index))
46334628
}
46344629
}
46354630
}
4636-
// If the traversal reaches the export, then the current node is not a sole dependent
4631+
// If the traversal reaches the export, then the current node is not a sole dependent and cannot be deleted
46374632
else {
46384633
can_delete = false;
4634+
break;
46394635
}
46404636
}
46414637
}

0 commit comments

Comments
 (0)