diff --git a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs index a2ad637ca..b7c709a95 100644 --- a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs +++ b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs @@ -1389,7 +1389,7 @@ namespace FlaxEditor.Surface.Archetypes var state = (StateMachineState)other; var action = new AddRemoveTransitionAction(this, state); - Surface?.Undo.AddAction(action); + Surface?.AddBatchedUndoAction(action); action.Do(); Surface?.OnNodesConnected(this, other); } @@ -1718,7 +1718,7 @@ namespace FlaxEditor.Surface.Archetypes public void Delete() { var action = new StateMachineState.AddRemoveTransitionAction(this); - SourceState.Surface?.Undo.AddAction(action); + SourceState.Surface?.AddBatchedUndoAction(action); action.Do(); } diff --git a/Source/Editor/Surface/Elements/Box.cs b/Source/Editor/Surface/Elements/Box.cs index ddf8e59d0..64594427b 100644 --- a/Source/Editor/Surface/Elements/Box.cs +++ b/Source/Editor/Surface/Elements/Box.cs @@ -437,7 +437,7 @@ namespace FlaxEditor.Surface.Elements var action = new EditNodeConnections(ParentNode.Context, ParentNode); RemoveConnections(1); action.End(); - Surface.Undo.AddAction(action); + Surface.AddBatchedUndoAction(action); } else { @@ -629,7 +629,7 @@ namespace FlaxEditor.Surface.Elements var action = new ConnectBoxesAction((InputBox)this, (OutputBox)connectedBox, false); BreakConnection(connectedBox); action.End(); - Surface.Undo.AddAction(action); + Surface.AddBatchedUndoAction(action); Surface.MarkAsEdited(); } else @@ -678,7 +678,7 @@ namespace FlaxEditor.Surface.Elements var action = new EditNodeConnections(ParentNode.Context, ParentNode); RemoveConnections(); action.End(); - Surface.Undo.AddAction(action); + Surface.AddBatchedUndoAction(action); } else { @@ -856,7 +856,7 @@ namespace FlaxEditor.Surface.Elements var action = new ConnectBoxesAction(iB, oB, false); start.BreakConnection(end); action.End(); - Surface.Undo.AddAction(action); + Surface.AddBatchedUndoAction(action); } else { @@ -892,7 +892,7 @@ namespace FlaxEditor.Surface.Elements var action = new ConnectBoxesAction(iB, oB, true); iB.CreateConnection(oB); action.End(); - Surface.Undo?.AddAction(action); + Surface.AddBatchedUndoAction(action); } else { diff --git a/Source/Editor/Surface/SurfaceNode.cs b/Source/Editor/Surface/SurfaceNode.cs index 5dc53caee..9f23e30cf 100644 --- a/Source/Editor/Surface/SurfaceNode.cs +++ b/Source/Editor/Surface/SurfaceNode.cs @@ -926,7 +926,8 @@ namespace FlaxEditor.Surface OnValuesChanged(); Surface?.MarkAsEdited(graphEdited); - Surface?.Undo?.AddAction(new EditNodeValuesAction(this, before, graphEdited)); + if (Surface?.Undo != null) + Surface.AddBatchedUndoAction(new EditNodeValuesAction(this, before, graphEdited)); _isDuringValuesEditing = false; } @@ -952,7 +953,8 @@ namespace FlaxEditor.Surface OnValuesChanged(); Surface.MarkAsEdited(graphEdited); - Surface.Undo?.AddAction(new EditNodeValuesAction(this, before, graphEdited)); + if (Surface?.Undo != null) + Surface.AddBatchedUndoAction(new EditNodeValuesAction(this, before, graphEdited)); _isDuringValuesEditing = false; } diff --git a/Source/Editor/Surface/VisjectSurface.Draw.cs b/Source/Editor/Surface/VisjectSurface.Draw.cs index 29da1d576..3616ee1d9 100644 --- a/Source/Editor/Surface/VisjectSurface.Draw.cs +++ b/Source/Editor/Surface/VisjectSurface.Draw.cs @@ -49,6 +49,13 @@ namespace FlaxEditor.Surface _moveViewWithMouseDragSpeed = isMovingWithMouse ? Mathf.Clamp(_moveViewWithMouseDragSpeed + deltaTime * 20.0f, 1.0f, 8.0f) : 1.0f; base.Update(deltaTime); + + // Batch undo actions + if (_batchedUndoActions != null && _batchedUndoActions.Count != 0) + { + Undo.AddAction(_batchedUndoActions.Count == 1 ? _batchedUndoActions[0] : new MultiUndoAction(_batchedUndoActions)); + _batchedUndoActions.Clear(); + } } /// diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs index 62c65ab49..88f81ded6 100644 --- a/Source/Editor/Surface/VisjectSurface.cs +++ b/Source/Editor/Surface/VisjectSurface.cs @@ -38,6 +38,7 @@ namespace FlaxEditor.Surface private VisjectCM _activeVisjectCM; private GroupArchetype _customNodesGroup; private List _customNodes; + private List _batchedUndoActions; private Action _onSave; private int _selectedConnectionIndex; @@ -901,6 +902,19 @@ namespace FlaxEditor.Surface { return _context.FindNode(id); } + + /// + /// Adds the undo action to be batched (eg. if multiple undo actions is performed in a sequence during single update). + /// + /// The action. + public void AddBatchedUndoAction(IUndoAction action) + { + if (Undo == null || !Undo.Enabled) + return; + if (_batchedUndoActions == null) + _batchedUndoActions = new List(); + _batchedUndoActions.Add(action); + } /// /// Called when node gets spawned in the surface (via UI).