mirror of
				https://github.com/lospec/pixel-editor.git
				synced 2023-08-10 21:12:51 +03:00 
			
		
		
		
	Added history management for duplicating layers
This commit is contained in:
		@@ -158,6 +158,27 @@ function HistoryStateRenameLayer(oldName, newName, layer) {
 | 
				
			|||||||
    saveHistoryState(this);
 | 
					    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) {
 | 
					function HistoryStateDeleteLayer(layerData, before, index) {
 | 
				
			||||||
    this.deleted = layerData;
 | 
					    this.deleted = layerData;
 | 
				
			||||||
    this.before = before;
 | 
					    this.before = before;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -460,7 +460,7 @@ function deleteLayer(saveHistory = true) {
 | 
				
			|||||||
    currentLayer.closeOptionsMenu();
 | 
					    currentLayer.closeOptionsMenu();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function duplicateLayer(event) {
 | 
					function duplicateLayer(event, saveHistory = true) {
 | 
				
			||||||
    let layerIndex = layers.indexOf(currentLayer);
 | 
					    let layerIndex = layers.indexOf(currentLayer);
 | 
				
			||||||
    let toDuplicate = currentLayer;
 | 
					    let toDuplicate = currentLayer;
 | 
				
			||||||
    let menuEntries = layerList.childNodes
 | 
					    let menuEntries = layerList.childNodes
 | 
				
			||||||
@@ -504,10 +504,9 @@ function duplicateLayer(event) {
 | 
				
			|||||||
        0, 0, currentLayer.canvasSize[0], currentLayer.canvasSize[1]), 0, 0);
 | 
					        0, 0, currentLayer.canvasSize[0], currentLayer.canvasSize[1]), 0, 0);
 | 
				
			||||||
    newLayer.updateLayerPreview();
 | 
					    newLayer.updateLayerPreview();
 | 
				
			||||||
    // Basically "if I'm not adding a layer because redo() is telling meto do so", then I can save the history
 | 
					    // Basically "if I'm not adding a layer because redo() is telling meto do so", then I can save the history
 | 
				
			||||||
    /*if (saveHistory) {
 | 
					    if (saveHistory) {
 | 
				
			||||||
        new HistoryStateDuplicateLayer(newLayer, index);
 | 
					        new HistoryStateDuplicateLayer(newLayer, currentLayer);
 | 
				
			||||||
    }*/
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function renameLayer(event) {
 | 
					function renameLayer(event) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user