Skip to content

Commit

Permalink
Found the proper fix of bug commit below lol
Browse files Browse the repository at this point in the history
  • Loading branch information
flabbet committed Dec 13, 2021
1 parent 54c3ae1 commit 099f0ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 4 additions & 7 deletions PixiEditor/Models/Controllers/UndoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,23 @@ public void Redo()
/// Merges multiple undo changes into one.
/// </summary>
/// <param name="amount">Amount of changes to squash.</param>
/// <param name="reverseOrderInReverseProcess">Reverses order of execution changes in reverseProcess (undo)</param>
public void SquashUndoChanges(int amount, bool reverseOrderInReverseProcess = false)
public void SquashUndoChanges(int amount)
{
string description = UndoStack.ElementAt(UndoStack.Count - amount).Description;
if (string.IsNullOrEmpty(description))
{
description = $"Squash {amount} undo changes.";
}

SquashUndoChanges(amount, description, reverseOrderInReverseProcess);
SquashUndoChanges(amount, description);
}

/// <summary>
/// Merges multiple undo changes into one.
/// </summary>
/// <param name="amount">Amount of changes to squash.</param>
/// <param name="description">Final change description.</param>
/// <param name="reverseOrderInReverseProcess">Reverses order of execution changes in reverseProcess (undo)</param>
public void SquashUndoChanges(int amount, string description, bool reverseOrderInReverseProcess = false)
public void SquashUndoChanges(int amount, string description)
{
Change[] changes = new Change[amount];
for (int i = 0; i < amount; i++)
Expand All @@ -131,8 +129,7 @@ public void SquashUndoChanges(int amount, string description, bool reverseOrderI

Action<object[]> reverseProcess = (object[] props) =>
{
IEnumerable<object> enumerable = reverseOrderInReverseProcess ? props.Reverse() : props;
foreach (var prop in enumerable)
foreach (var prop in props)
{
Change change = (Change)prop;
if (change.ReverseProcess == null)
Expand Down
2 changes: 1 addition & 1 deletion PixiEditor/Models/DataHolders/Document/Document.Layers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ private void DisposeLayerBitmaps()
renderer?.Dispose();
}

private void BuildLayerStructureProcess(object[] parameters)
public void BuildLayerStructureProcess(object[] parameters)
{
if (parameters.Length > 0 && parameters[0] is WpfObservableRangeCollection<GuidStructureItem> groups)
{
Expand Down
12 changes: 9 additions & 3 deletions PixiEditor/Models/Tools/BitmapOperationTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ public override void AfterUse()
return;
var document = ViewModels.ViewModelMain.Current.BitmapManager.ActiveDocument;
var args = new object[] { _change.Document };
document.UndoManager.AddUndoChange(_change.ToChange(StorageBasedChange.BasicUndoProcess, args));
document.AddLayerStructureToUndo(document.LayerStructure.CloneGroups());
document.UndoManager.SquashUndoChanges(2, true);
document.UndoManager.AddUndoChange(_change.ToChange(UndoStorageBasedChange, args));
_change = null;
}

private void UndoStorageBasedChange(Layer[] layers, UndoLayer[] data, object[] args)
{
Document document = (Document)args[0];
var ls = document.LayerStructure.CloneGroups();
StorageBasedChange.BasicUndoProcess(layers, data, args);
document.BuildLayerStructureProcess(new object[] { ls });
}
}
}

0 comments on commit 099f0ab

Please sign in to comment.