mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Fixed canvas resizing history bug
This commit is contained in:
parent
50d63026da
commit
f0fae3698d
@ -46,7 +46,7 @@ function HistoryStateResizeCanvas(newSize, oldSize, imageDatas, trim) {
|
|||||||
let dataIndex = 0;
|
let dataIndex = 0;
|
||||||
console.log("breakpoint");
|
console.log("breakpoint");
|
||||||
// Resizing the canvas
|
// Resizing the canvas
|
||||||
resizeCanvas(null, oldSize);
|
resizeCanvas(null, oldSize, null, false);
|
||||||
// Putting the image datas
|
// Putting the image datas
|
||||||
for (let i=0; i<layers.length; i++) {
|
for (let i=0; i<layers.length; i++) {
|
||||||
if (layers[i].menuEntry != null) {
|
if (layers[i].menuEntry != null) {
|
||||||
@ -61,8 +61,7 @@ function HistoryStateResizeCanvas(newSize, oldSize, imageDatas, trim) {
|
|||||||
this.redo = function() {
|
this.redo = function() {
|
||||||
console.log("trim: " + this.trim);
|
console.log("trim: " + this.trim);
|
||||||
if (!this.trim) {
|
if (!this.trim) {
|
||||||
resizeCanvas(null, newSize);
|
resizeCanvas(null, newSize, null, false);
|
||||||
undoStates.push(this);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
trimCanvas(null, false);
|
trimCanvas(null, false);
|
||||||
|
@ -60,7 +60,7 @@ function rcChangedSize(event) {
|
|||||||
borders.bottom = bottom;
|
borders.bottom = bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resizeCanvas(event, size, customData, saveHistory) {
|
function resizeCanvas(event, size, customData, saveHistory = true) {
|
||||||
let imageDatas = [];
|
let imageDatas = [];
|
||||||
let leftOffset = 0;
|
let leftOffset = 0;
|
||||||
let topOffset = 0;
|
let topOffset = 0;
|
||||||
@ -84,7 +84,7 @@ function resizeCanvas(event, size, customData, saveHistory) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Saving the history only if I'm not already undoing or redoing
|
// Saving the history only if I'm not already undoing or redoing
|
||||||
if (size == undefined && (saveHistory != null && saveHistory)) {
|
if (saveHistory) {
|
||||||
// Saving history
|
// Saving history
|
||||||
new HistoryStateResizeCanvas(
|
new HistoryStateResizeCanvas(
|
||||||
{x: parseInt(layers[0].canvasSize[0]) + borders.left + borders.right,
|
{x: parseInt(layers[0].canvasSize[0]) + borders.left + borders.right,
|
||||||
@ -92,8 +92,10 @@ function resizeCanvas(event, size, customData, saveHistory) {
|
|||||||
|
|
||||||
{x: layers[0].canvasSize[0],
|
{x: layers[0].canvasSize[0],
|
||||||
y: layers[0].canvasSize[1]},
|
y: layers[0].canvasSize[1]},
|
||||||
imageDatas.slice(), imageDatas != undefined && saveHistory != undefined && saveHistory
|
imageDatas.slice(), customData != null && saveHistory
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log("salvata");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize the canvases
|
// Resize the canvases
|
||||||
@ -182,6 +184,7 @@ function trimCanvas(event, saveHistory) {
|
|||||||
let tmp;
|
let tmp;
|
||||||
let imageDatas = [];
|
let imageDatas = [];
|
||||||
let historySave = saveHistory == null;
|
let historySave = saveHistory == null;
|
||||||
|
let prevPivot = rcPivot;
|
||||||
|
|
||||||
rcPivot = "topleft";
|
rcPivot = "topleft";
|
||||||
console.log("debug");
|
console.log("debug");
|
||||||
@ -244,6 +247,8 @@ function trimCanvas(event, saveHistory) {
|
|||||||
document.getElementById("rc-border-bottom").value = borders.bottom;
|
document.getElementById("rc-border-bottom").value = borders.bottom;
|
||||||
|
|
||||||
resizeCanvas(null, null, imageDatas.slice(), historySave);
|
resizeCanvas(null, null, imageDatas.slice(), historySave);
|
||||||
|
// Resetting the previous pivot
|
||||||
|
rcPivot = prevPivot;
|
||||||
}
|
}
|
||||||
|
|
||||||
function rcUpdateBorders() {
|
function rcUpdateBorders() {
|
||||||
|
Loading…
Reference in New Issue
Block a user