Browse Source

Fixed copying multiple layers and a crash

Krzysztof Krysiński 1 week ago
parent
commit
559bd8571e

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changes/Structure/ImportLayer_Change.cs

@@ -61,7 +61,7 @@ internal class ImportLayer_Change : Change
 
         var clone = (LayerNode)layerNode.Clone();
         clone.Id = duplicateGuid;
-        clonedLayer = clone;
+        clonedLayer ??= clone.Clone(true) as LayerNode;
 
         ResizeImageData(clone, target.Size);
 

+ 7 - 3
src/PixiEditor/Models/Controllers/ClipboardController.cs

@@ -252,7 +252,7 @@ internal static class ClipboardController
         if (images.Count == 0)
             return false;
 
-        if (images.Count == 1)
+        if (images.Count == 1 || (images.Count > 1 && !pasteAsNew))
         {
             var dataImage = images[0];
             var position = dataImage.Position;
@@ -409,14 +409,17 @@ internal static class ClipboardController
 
         VecD pos = VecD.Zero;
 
+        string? importingType = null;
+
         foreach (var dataObject in data)
         {
-            if (TryExtractSingleImage(dataObject, out var singleImage))
+            if (importingType is null or "bytes" && TryExtractSingleImage(dataObject, out var singleImage))
             {
                 surfaces.Add(new DataImage(singleImage,
                     dataObject.Contains(ClipboardDataFormats.PositionFormat)
                         ? (VecI)dataObject.GetVecD(ClipboardDataFormats.PositionFormat)
                         : (VecI)pos));
+                importingType = "bytes";
                 continue;
             }
 
@@ -436,7 +439,7 @@ internal static class ClipboardController
                 paths.Add(textPath);
             }
 
-            if (paths == null || paths.Count == 0)
+            if (paths == null || paths.Count == 0 || (importingType != null && importingType != "files"))
             {
                 continue;
             }
@@ -463,6 +466,7 @@ internal static class ClipboardController
                     string filename = Path.GetFullPath(path);
                     surfaces.Add(new DataImage(filename, imported,
                         (VecI)dataObject.GetVecD(ClipboardDataFormats.PositionFormat)));
+                    importingType = "files";
                 }
                 catch
                 {

+ 3 - 1
src/PixiEditor/Models/DocumentModels/Public/DocumentOperationsModule.cs

@@ -149,6 +149,8 @@ internal class DocumentOperationsModule : IDocumentOperations
 
         Internals.ChangeController.TryStopActiveExecutor();
 
+        var changeBlock = Document.Operations.StartChangeBlock();
+
         RectI maxSize = new RectI(VecI.Zero, Document.SizeBindable);
         foreach (var imageWithName in images)
         {
@@ -167,7 +169,7 @@ internal class DocumentOperationsModule : IDocumentOperations
                 layerGuid, true, false, frame, false);
         }
 
-        Internals.ActionAccumulator.AddFinishedActions();
+        changeBlock.Dispose();
     }
 
     /// <summary>