@@ -3186,6 +3186,15 @@ var el in
31863186
31873187 ClipBoard . AddRange ( connectors ) ;
31883188 }
3189+
3190+ var connectorPins = ClipBoard
3191+ . OfType < ConnectorModel > ( )
3192+ . SelectMany ( connector => connector . ConnectorPinModels )
3193+ . Where ( pin => ! ClipBoard . Contains ( pin ) )
3194+ . Cast < ModelBase > ( )
3195+ . ToList ( ) ;
3196+
3197+ ClipBoard . AddRange ( connectorPins ) ;
31893198 }
31903199
31913200 /// <summary>
@@ -3235,6 +3244,7 @@ public void Paste(Point2D targetPoint, bool useOffset = true)
32353244
32363245 var nodes = ClipBoard . OfType < NodeModel > ( ) ;
32373246 var connectors = ClipBoard . OfType < ConnectorModel > ( ) ;
3247+ var connectorPins = ClipBoard . OfType < ConnectorPinModel > ( ) ;
32383248 var notes = ClipBoard . OfType < NoteModel > ( ) ;
32393249 // we only want to get groups that either has nested groups
32403250 // or does not belong to a group here.
@@ -3329,27 +3339,59 @@ public void Paste(Point2D targetPoint, bool useOffset = true)
33293339
33303340 ModelBase start ;
33313341 ModelBase end ;
3332- var newConnectors =
3333- from c in connectors
33343342
3335- // If the guid is in nodeLookup, then we connect to the new pasted node. Otherwise we
3336- // re-connect to the original.
3337- let startNode =
3343+ var newConnectors = new List < ConnectorModel > ( ) ;
3344+ var connectorLookup = new Dictionary < Guid , ConnectorModel > ( ) ;
3345+ foreach ( var c in connectors )
3346+ {
3347+ // If the guid is in nodeLookup, then we connect to the new pasted node. Otherwise we
3348+ // re-connect to the original.
3349+ var startNode =
33383350 modelLookup . TryGetValue ( c . Start . Owner . GUID , out start )
33393351 ? start as NodeModel
3340- : CurrentWorkspace . Nodes . FirstOrDefault ( x => x . GUID == c . Start . Owner . GUID )
3341- let endNode =
3352+ : CurrentWorkspace . Nodes . FirstOrDefault ( x => x . GUID == c . Start . Owner . GUID ) ;
3353+ var endNode =
33423354 modelLookup . TryGetValue ( c . End . Owner . GUID , out end )
33433355 ? end as NodeModel
3344- : CurrentWorkspace . Nodes . FirstOrDefault ( x => x . GUID == c . End . Owner . GUID )
3356+ : CurrentWorkspace . Nodes . FirstOrDefault ( x => x . GUID == c . End . Owner . GUID ) ;
33453357
33463358 // Don't make a connector if either end is null.
3347- where startNode != null && endNode != null
3348- select
3349- ConnectorModel . Make ( startNode , endNode , c . Start . Index , c . End . Index ) ;
3359+ if ( startNode == null || endNode == null )
3360+ {
3361+ continue ;
3362+ }
3363+ var newConnector = ConnectorModel . Make ( startNode , endNode , c . Start . Index , c . End . Index ) ;
3364+ if ( newConnector != null )
3365+ {
3366+ newConnectors . Add ( newConnector ) ;
3367+ connectorLookup . Add ( c . GUID , newConnector ) ;
3368+ }
3369+ }
33503370
33513371 createdModels . AddRange ( newConnectors ) ;
33523372
3373+ var newConnectorPins = new List < ConnectorPinModel > ( ) ;
3374+ foreach ( var pin in connectorPins )
3375+ {
3376+ if ( ! connectorLookup . TryGetValue ( pin . ConnectorId , out var connector ) )
3377+ {
3378+ continue ;
3379+ }
3380+
3381+ var copiedPin = new ConnectorPinModel
3382+ (
3383+ pin . Position . X + shiftX + offset ,
3384+ pin . Position . Y + shiftY + offset ,
3385+ Guid . NewGuid ( ) ,
3386+ connector . GUID
3387+ ) ;
3388+
3389+ connector . AddPin ( copiedPin ) ;
3390+ newConnectorPins . Add ( copiedPin ) ;
3391+ }
3392+
3393+ createdModels . AddRange ( newConnectorPins ) ;
3394+
33533395 //Grouping depends on the selected node models.
33543396 //so adding the group after nodes / notes are added to workspace.
33553397 //select only those nodes that are part of a group.
@@ -3399,6 +3441,12 @@ from c in connectors
33993441 AddToSelection ( item ) ;
34003442 }
34013443
3444+ // Keep connector pins selected together with the pasted graph chunk
3445+ foreach ( var connectorPin in newConnectorPins )
3446+ {
3447+ AddToSelection ( connectorPin ) ;
3448+ }
3449+
34023450 DynamoSelection . Instance . ClearSelectionDisabled = false ;
34033451
34043452 // Record models that are created as part of the command.
0 commit comments