Skip to content

Commit 89f08fb

Browse files
committed
Fix deletion
1 parent 2f45cf7 commit 89f08fb

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
@@ -4610,37 +4610,33 @@ impl NodeNetworkInterface {
46104610
continue;
46114611
};
46124612

4613+
// Perform an upstream traversal to try delete children
46134614
for upstream_id in self.upstream_flow_back_from_nodes(vec![*node_id], network_path, FlowType::LayerChildrenUpstreamFlow) {
4614-
// This does a downstream traversal starting from the current node, and ending at either a node in the `delete_nodes` set or the output.
4615-
// 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.
4615+
// 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.
4616+
// If the output node is eventually reached, then it is not a sole dependent and will not be deleted
46164617
let mut stack = vec![OutputConnector::node(upstream_id, 0)];
46174618
let mut can_delete = true;
46184619
while let Some(current_node) = stack.pop() {
46194620
let current_node_id = current_node.node_id().expect("The current node in the delete stack cannot be the export");
46204621
let Some(downstream_nodes) = outward_wires.get(&current_node) else { continue };
4622+
// If there are no outward wires, then we have reached a dead end, and the node cannot be deleted
4623+
if downstream_nodes.is_empty() {
4624+
can_delete = false;
4625+
break;
4626+
}
46214627
for downstream_node in downstream_nodes {
46224628
if let InputConnector::Node { node_id: downstream_id, .. } = downstream_node {
4629+
// If the downstream node is not in the delete nodes set, then continue iterating
46234630
if !delete_nodes.contains(downstream_id) {
4624-
can_delete = false;
4625-
break;
4626-
}
4627-
// 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
4628-
else {
4629-
for deleted_node_id in &nodes_to_delete {
4630-
let Some(downstream_node) = self.document_node(deleted_node_id, network_path) else { continue };
4631-
let Some(input) = downstream_node.inputs.first() else { continue };
4632-
4633-
if let NodeInput::Node { node_id, .. } = input {
4634-
if *node_id == current_node_id {
4635-
stack.push(OutputConnector::node(*deleted_node_id, 0));
4636-
}
4637-
}
4631+
for output_index in 0..self.number_of_outputs(downstream_id, network_path) {
4632+
stack.push(OutputConnector::node(*downstream_id, output_index))
46384633
}
46394634
}
46404635
}
4641-
// If the traversal reaches the export, then the current node is not a sole dependent
4636+
// If the traversal reaches the export, then the current node is not a sole dependent and cannot be deleted
46424637
else {
46434638
can_delete = false;
4639+
break;
46444640
}
46454641
}
46464642
}

0 commit comments

Comments
 (0)