Skip to content

Commit

Permalink
Fix move tool undo crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Dec 18, 2021
1 parent 12c0e3d commit 40c444d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 32 deletions.
14 changes: 2 additions & 12 deletions PixiEditor/Models/Tools/BitmapOperationTool.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using PixiEditor.Models.DataHolders;
using PixiEditor.Models.DataHolders;
using PixiEditor.Models.Layers;
using PixiEditor.Models.Position;
using PixiEditor.Models.Undo;
using SkiaSharp;
using System.Collections.Generic;
using PixiEditor.Models.Tools.ToolSettings.Settings;

namespace PixiEditor.Models.Tools
{
Expand Down Expand Up @@ -47,7 +45,7 @@ public override void AfterUse(SKRectI sessionRect)

var document = ViewModels.ViewModelMain.Current.BitmapManager.ActiveDocument;
var args = new object[] { _change.Document };
document.UndoManager.AddUndoChange(_change.ToChange(UndoStorageBasedChange, args));
document.UndoManager.AddUndoChange(_change.ToChange(StorageBasedChange.BasicUndoProcess, args));
_change = null;
}

Expand Down Expand Up @@ -75,13 +73,5 @@ private void InitializeStorageBasedChange(SKRectI toolSessionRect)

_change = new StorageBasedChange(doc, new[] { doc.ActiveLayer });
}

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 });
}
}
}
21 changes: 1 addition & 20 deletions PixiEditor/Models/Tools/Tools/MoveTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private static void ApplySurfacesToLayers(Surface[] surfaces, Coordinates[] star
private void SaveUndo(Document document)
{
var args = new object[] { change.Document };
document.UndoManager.AddUndoChange(change.ToChange(UndoProcess, args));
document.UndoManager.AddUndoChange(change.ToChange(StorageBasedChange.BasicUndoProcess, args));
if (moveStartSelectedPoints != null)
{
SelectionHelpers.AddSelectionUndoStep(document, moveStartSelectedPoints, SelectionType.New);
Expand All @@ -192,24 +192,5 @@ private void SaveUndo(Document document)
}
change = null;
}

private void UndoProcess(Layer[] layers, UndoLayer[] data, object[] args)
{
if (args.Length > 0 && args[0] is Document document)
{
for (int i = 0; i < layers.Length; i++)
{
Layer layer = layers[i];
document.Layers.RemoveAt(data[i].LayerIndex);

document.Layers.Insert(data[i].LayerIndex, layer);
if (data[i].IsActive)
{
document.SetMainActiveLayer(data[i].LayerIndex);
}
}

}
}
}
}
3 changes: 3 additions & 0 deletions PixiEditor/Models/Undo/StorageBasedChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ public static void BasicUndoProcess(Layer[] layers, UndoLayer[] data, object[] a
{
if (args.Length > 0 && args[0] is Document document)
{
var ls = document.LayerStructure.CloneGroups();

for (int i = 0; i < layers.Length; i++)
{
Layer layer = layers[i];
Expand All @@ -286,6 +288,7 @@ public static void BasicUndoProcess(Layer[] layers, UndoLayer[] data, object[] a
}
}

document.BuildLayerStructureProcess(new object[] { ls });
}
}
}
Expand Down

0 comments on commit 40c444d

Please sign in to comment.