From 2a5315b81a5bdd0357399754ce21113f0ee1972d Mon Sep 17 00:00:00 2001 From: unsettledgames <47360416+unsettledgames@users.noreply.github.com> Date: Thu, 17 Sep 2020 12:36:15 +0200 Subject: [PATCH] Added history management for duplicating layers --- js/_history.js | 21 +++++++++++++++++++++ js/_layer.js | 9 ++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/js/_history.js b/js/_history.js index 881e373..ab69648 100644 --- a/js/_history.js +++ b/js/_history.js @@ -158,6 +158,27 @@ function HistoryStateRenameLayer(oldName, newName, layer) { saveHistoryState(this); } +function HistoryStateDuplicateLayer(addedLayer, copiedLayer) { + this.addedLayer = addedLayer; + this.copiedLayer = copiedLayer; + + this.undo = function() { + addedLayer.selectLayer(); + deleteLayer(false); + + redoStates.push(this); + }; + + this.redo = function() { + copiedLayer.selectLayer(); + duplicateLayer(null, false); + + undoStates.push(this); + }; + + saveHistoryState(this); +} + function HistoryStateDeleteLayer(layerData, before, index) { this.deleted = layerData; this.before = before; diff --git a/js/_layer.js b/js/_layer.js index e875443..ca0f241 100644 --- a/js/_layer.js +++ b/js/_layer.js @@ -460,7 +460,7 @@ function deleteLayer(saveHistory = true) { currentLayer.closeOptionsMenu(); } -function duplicateLayer(event) { +function duplicateLayer(event, saveHistory = true) { let layerIndex = layers.indexOf(currentLayer); let toDuplicate = currentLayer; let menuEntries = layerList.childNodes @@ -504,10 +504,9 @@ function duplicateLayer(event) { 0, 0, currentLayer.canvasSize[0], currentLayer.canvasSize[1]), 0, 0); newLayer.updateLayerPreview(); // Basically "if I'm not adding a layer because redo() is telling meto do so", then I can save the history - /*if (saveHistory) { - new HistoryStateDuplicateLayer(newLayer, index); - }*/ - + if (saveHistory) { + new HistoryStateDuplicateLayer(newLayer, currentLayer); + } } function renameLayer(event) {