mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 17:03:32 +03:00
Remove connections for a node that is being deleted. (#7185)
Fixes https://github.com/enso-org/enso/issues/7135 https://github.com/enso-org/enso/assets/1428930/85433a69-03dc-4ad9-9563-717a78ff6ff8
This commit is contained in:
parent
78545b4402
commit
cd7f17a0e4
@ -283,6 +283,16 @@ impl Connections {
|
||||
target: Self::convert_endpoint(&connection.target),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return all connections that involve the given node.
|
||||
pub fn with_node(&self, node: node::Id) -> impl Iterator<Item = Connection> {
|
||||
self.connections
|
||||
.iter()
|
||||
.filter(move |conn| conn.source.node == node || conn.target.node == node)
|
||||
.copied()
|
||||
.collect_vec()
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -451,6 +451,21 @@ impl Handle {
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove all the connections from the graph. This is a convenience method that calls
|
||||
/// [`disconnect`] for each connection. If any of the calls fails, the first error is
|
||||
/// propagated, but all the connections are attempted to be disconnected.
|
||||
pub fn disconnect_all(&self, connections: impl Iterator<Item = Connection>) -> FallibleResult {
|
||||
let errors =
|
||||
connections.map(|c| self.disconnect(&c)).filter_map(|r| r.err()).collect::<Vec<_>>();
|
||||
// Failure has no good way to propagate multiple errors with `Failure`. So we propagate
|
||||
// only the first one.
|
||||
if let Some(error) = errors.into_iter().next() {
|
||||
Err(error)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the execution environment.
|
||||
pub async fn set_execution_environment(
|
||||
&self,
|
||||
|
@ -292,6 +292,17 @@ impl Model {
|
||||
|| {
|
||||
let ast_id = self.state.update_from_view().remove_node(id)?;
|
||||
self.widget.remove_all_node_widgets(ast_id);
|
||||
|
||||
let connections = self.controller.connections();
|
||||
let node_connections = connections.map(|c| c.with_node(ast_id));
|
||||
let disconnect_result = node_connections.map(|c| self.controller.disconnect_all(c));
|
||||
if let Err(e) = disconnect_result {
|
||||
warn!(
|
||||
"Failed to disconnect all connections from node {:?} because of {:?}",
|
||||
ast_id, e
|
||||
);
|
||||
}
|
||||
|
||||
Some(self.controller.graph().remove_node(ast_id))
|
||||
},
|
||||
"remove node",
|
||||
|
Loading…
Reference in New Issue
Block a user