@@ -1496,19 +1496,25 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
14961496 for input_index in 0 ..network_interface. number_of_inputs ( selected_node, selection_network_path) {
14971497 let input_connector = InputConnector :: node ( * selected_node, input_index) ;
14981498 // Only disconnect inputs to non selected nodes
1499- if network_interface
1499+ if ! network_interface
15001500 . upstream_output_connector ( & input_connector, selection_network_path)
15011501 . and_then ( |connector| connector. node_id ( ) )
1502- . is_some_and ( |node_id| ! all_selected_nodes. contains ( & node_id) )
1502+ . is_some_and ( |node_id| all_selected_nodes. contains ( & node_id) )
15031503 {
15041504 responses. add ( NodeGraphMessage :: DisconnectInput { input_connector } ) ;
15051505 }
15061506 }
15071507
15081508 let number_of_outputs = network_interface. number_of_outputs ( selected_node, selection_network_path) ;
1509- let first_deselected_upstream_node = network_interface
1510- . upstream_flow_back_from_nodes ( vec ! [ * selected_node] , selection_network_path, FlowType :: PrimaryFlow )
1511- . find ( |upstream_node| !all_selected_nodes. contains ( upstream_node) ) ;
1509+ let mut first_deselected_upstream_output = network_interface. upstream_output_connector ( & InputConnector :: node ( * selected_node, 0 ) , selection_network_path) ;
1510+ while let Some ( OutputConnector :: Node { node_id, .. } ) = & first_deselected_upstream_output {
1511+ if !all_selected_nodes. contains ( node_id) {
1512+ break ;
1513+ }
1514+
1515+ first_deselected_upstream_output = network_interface. upstream_output_connector ( & InputConnector :: node ( * node_id, 0 ) , selection_network_path) ;
1516+ }
1517+
15121518 let Some ( outward_wires) = network_interface. outward_wires ( selection_network_path) else {
15131519 log:: error!( "Could not get output wires in shake input" ) ;
15141520 continue ;
@@ -1528,46 +1534,26 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
15281534
15291535 // Handle reconnection
15301536 // Find first non selected upstream node by primary flow
1531- if let Some ( first_deselected_upstream_node ) = first_deselected_upstream_node {
1537+ if let Some ( first_deselected_upstream_output ) = first_deselected_upstream_output {
15321538 let Some ( downstream_connections_to_first_output) = outward_wires. get ( & OutputConnector :: node ( * selected_node, 0 ) ) . cloned ( ) else {
15331539 log:: error!( "Could not get downstream_connections_to_first_output in shake node" ) ;
15341540 return ;
15351541 } ;
15361542 // Reconnect only if all downstream outputs are not selected
1537- if !downstream_connections_to_first_output
1538- . iter ( )
1539- . any ( |connector| connector. node_id ( ) . is_some_and ( |node_id| all_selected_nodes. contains ( & node_id) ) )
1540- {
1541- // Find what output on the deselected upstream node to reconnect to
1542- for output_index in 0 ..network_interface. number_of_outputs ( & first_deselected_upstream_node, selection_network_path) {
1543- let output_connector = & OutputConnector :: node ( first_deselected_upstream_node, output_index) ;
1544- let Some ( outward_wires) = network_interface. outward_wires ( selection_network_path) else {
1545- log:: error!( "Could not get output wires in shake input" ) ;
1546- continue ;
1547- } ;
1548- if let Some ( inputs) = outward_wires. get ( output_connector) {
1549- // This can only run once
1550- if inputs. iter ( ) . any ( |input_connector| {
1551- input_connector
1552- . node_id ( )
1553- . is_some_and ( |upstream_node| all_selected_nodes. contains ( & upstream_node) && input_connector. input_index ( ) == 0 )
1554- } ) {
1555- // Output index is the output of the deselected upstream node to reconnect to
1556- for downstream_connections_to_first_output in & downstream_connections_to_first_output {
1557- responses. add ( NodeGraphMessage :: CreateWire {
1558- output_connector : OutputConnector :: node ( first_deselected_upstream_node, output_index) ,
1559- input_connector : * downstream_connections_to_first_output,
1560- } ) ;
1561- }
1562- }
1563- }
1564-
1565- // Set all chain nodes back to chain position
1566- // TODO: Fix
1567- // for chain_node_to_reset in std::mem::take(&mut self.drag_start_chain_nodes) {
1568- // responses.add(NodeGraphMessage::SetChainPosition { node_id: chain_node_to_reset });
1569- // }
1543+ for downstream_connection_to_first_output in & downstream_connections_to_first_output {
1544+ if !downstream_connection_to_first_output. node_id ( ) . is_some_and ( |node_id| all_selected_nodes. contains ( & node_id) ) {
1545+ // Reconnect the upstream output to all downstream inputs
1546+ responses. add ( NodeGraphMessage :: CreateWire {
1547+ output_connector : first_deselected_upstream_output,
1548+ input_connector : * downstream_connection_to_first_output,
1549+ } ) ;
15701550 }
1551+
1552+ // Set all chain nodes back to chain position
1553+ // TODO: Fix
1554+ // for chain_node_to_reset in std::mem::take(&mut self.drag_start_chain_nodes) {
1555+ // responses.add(NodeGraphMessage::SetChainPosition { node_id: chain_node_to_reset });
1556+ // }
15711557 }
15721558 }
15731559 }
0 commit comments