static State MergeStack(State previousState, MergeStackAction action) { VSGraphModel graphModel = (VSGraphModel)previousState.CurrentGraphModel; var stackModelA = (StackBaseModel)action.StackModelA; var stackModelB = (StackBaseModel)action.StackModelB; Undo.RegisterCompleteObjectUndo((Object)graphModel.AssetModel, "Move stacked nodes"); // Move all nodes from stackB to stackA stackModelA.MoveStackedNodes(stackModelB.NodeModels.ToList(), -1, false); // Move output connections of stackB to stackA var previousEdgeConnections = graphModel.GetEdgesConnections(stackModelB.OutputPorts.First()).ToList(); foreach (var edge in previousEdgeConnections) { graphModel.CreateEdge(edge.InputPortModel, stackModelA.OutputPorts.First()); } // Delete stackB graphModel.DeleteNode(stackModelB, GraphModel.DeleteConnections.True); previousState.MarkForUpdate(UpdateFlags.GraphTopology); return(previousState); }