Add batching undo actions for Surface editing to prevent undo actions spam during a single edit

This commit is contained in:
Wojtek Figat
2022-07-19 23:07:18 +02:00
parent fd4af3964d
commit f90808749e
5 changed files with 32 additions and 9 deletions

View File

@@ -38,6 +38,7 @@ namespace FlaxEditor.Surface
private VisjectCM _activeVisjectCM;
private GroupArchetype _customNodesGroup;
private List<NodeArchetype> _customNodes;
private List<IUndoAction> _batchedUndoActions;
private Action _onSave;
private int _selectedConnectionIndex;
@@ -901,6 +902,19 @@ namespace FlaxEditor.Surface
{
return _context.FindNode(id);
}
/// <summary>
/// Adds the undo action to be batched (eg. if multiple undo actions is performed in a sequence during single update).
/// </summary>
/// <param name="action">The action.</param>
public void AddBatchedUndoAction(IUndoAction action)
{
if (Undo == null || !Undo.Enabled)
return;
if (_batchedUndoActions == null)
_batchedUndoActions = new List<IUndoAction>();
_batchedUndoActions.Add(action);
}
/// <summary>
/// Called when node gets spawned in the surface (via UI).