From 7eaae15ff3bdf1700a56ddefa833d557a73a0f33 Mon Sep 17 00:00:00 2001 From: Skyler Lehmkuhl Date: Mon, 13 Jan 2025 20:08:58 -0500 Subject: [PATCH] Fix pasting multiple times --- src/main.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index 710be1b..7af2103 100644 --- a/src/main.js +++ b/src/main.js @@ -705,8 +705,32 @@ let actions = { duplicateObject: { create: (items) => { redoStack.length = 0; + function deepCopyWithIdxMapping(obj, dictionary = {}) { + if (Array.isArray(obj)) { + return obj.map(item => deepCopyWithIdxMapping(item, dictionary)); + } + if (obj === null || typeof obj !== 'object') { + return obj; + } + + const newObj = {}; + for (const key in obj) { + let value = obj[key]; + + if (key === 'idx' && !(value in dictionary)) { + dictionary[value] = uuidv4(); + } + + newObj[key] = value in dictionary ? dictionary[value] : value; + if (typeof newObj[key] === 'object' && newObj[key] !== null) { + newObj[key] = deepCopyWithIdxMapping(newObj[key], dictionary); + } + } + + return newObj; + } let action = { - items: items, + items: deepCopyWithIdxMapping(items), object: context.activeObject.idx, frame: context.activeObject.currentFrame.idx, uuid: uuidv4(), @@ -3315,7 +3339,11 @@ class Shape extends BaseShape { // } newShape.updateVertices(); newShape.fillStyle = this.fillStyle; - newShape.fillImage = this.fillImage; + if (this.fillImage instanceof Element) { + newShape.fillImage = this.fillImage.cloneNode(true) + } else { + newShape.fillImage = this.fillImage; + } newShape.strokeStyle = this.strokeStyle; newShape.lineWidth = this.lineWidth; newShape.filled = this.filled;