@@ -369,13 +369,8 @@ impl NodeNetworkInterface {
369369 return None ;
370370 } ;
371371 // TODO: Get downstream connections from all outputs
372- let Some ( downstream_connections) = outward_wires. get ( & OutputConnector :: node ( * node_id, 0 ) ) else {
373- log:: error!( "Could not get outward wires in copy_nodes" ) ;
374- return None ;
375- } ;
376- let has_selected_node_downstream = downstream_connections
377- . iter ( )
378- . any ( |input_connector| input_connector. node_id ( ) . is_some_and ( |upstream_id| new_ids. keys ( ) . any ( |key| * key == upstream_id) ) ) ;
372+ let mut downstream_connections = outward_wires. get ( & OutputConnector :: node ( * node_id, 0 ) ) . map_or ( [ ] . iter ( ) , |outputs| outputs. iter ( ) ) ;
373+ let has_selected_node_downstream = downstream_connections. any ( |input_connector| input_connector. node_id ( ) . is_some_and ( |upstream_id| new_ids. keys ( ) . any ( |key| * key == upstream_id) ) ) ;
379374 // If the copied node does not have a downstream connection to another copied node, then set the position to absolute
380375 if !has_selected_node_downstream {
381376 let Some ( position) = self . position ( node_id, network_path) else {
@@ -6916,3 +6911,34 @@ pub enum TransactionStatus {
69166911 #[ default]
69176912 Finished ,
69186913}
6914+
6915+ #[ cfg( test) ]
6916+ mod network_interface_tests {
6917+ use crate :: test_utils:: test_prelude:: * ;
6918+ #[ tokio:: test]
6919+ async fn copy_isolated_node ( ) {
6920+ let mut editor = EditorTestUtils :: create ( ) ;
6921+ editor. new_document ( ) . await ;
6922+ let rectangle = editor. create_node_by_name ( "Rectangle" ) . await ;
6923+ editor. handle_message ( NodeGraphMessage :: SelectedNodesSet { nodes : vec ! [ rectangle] } ) . await ;
6924+ let frontend_messages = editor. handle_message ( NodeGraphMessage :: Copy ) . await ;
6925+ let serialized_nodes = frontend_messages
6926+ . into_iter ( )
6927+ . find_map ( |msg| match msg {
6928+ FrontendMessage :: TriggerTextCopy { copy_text } => Some ( copy_text) ,
6929+ _ => None ,
6930+ } )
6931+ . expect ( "copy message should be dispatched" )
6932+ . strip_prefix ( "graphite/nodes: " )
6933+ . expect ( "should start with magic string" )
6934+ . to_string ( ) ;
6935+ println ! ( "Serialized: {serialized_nodes}" ) ;
6936+ editor. handle_message ( NodeGraphMessage :: PasteNodes { serialized_nodes } ) . await ;
6937+ let nodes = & mut editor. active_document_mut ( ) . network_interface . network_mut ( & [ ] ) . unwrap ( ) . nodes ;
6938+ let orignal = nodes. remove ( & rectangle) . expect ( "original node should exist" ) ;
6939+ assert ! (
6940+ nodes. values( ) . any( |other| * other == orignal) ,
6941+ "duplicated node should exist\n other nodes: {nodes:#?}\n orignal {orignal:#?}"
6942+ ) ;
6943+ }
6944+ }
0 commit comments