Repair Undo/Redo in Masking Mode

This commit is contained in:
Dariusz L
2025-08-08 22:41:19 +02:00
parent afdac52144
commit 949ffa0143
4 changed files with 60 additions and 24 deletions

View File

@@ -1352,6 +1352,23 @@ export class MaskTool {
this.canvasInstance.render();
log.info("Cleared all mask data from all chunks");
}
/**
* Clears all chunks and restores mask from saved state
* This is used during undo/redo operations to ensure clean state restoration
*/
restoreMaskFromSavedState(savedMaskCanvas) {
// First, clear ALL chunks to ensure no leftover data
this.clearAllMaskChunks();
// Now apply the saved mask state to chunks
if (savedMaskCanvas.width > 0 && savedMaskCanvas.height > 0) {
// Apply the saved mask to the chunk system at the correct position
const bounds = this.canvasInstance.outputAreaBounds;
this.applyMaskCanvasToChunks(savedMaskCanvas, this.x, this.y);
}
// Update the active mask canvas to show the restored state
this.updateActiveMaskCanvas(true);
log.debug("Restored mask from saved state with clean chunk system");
}
getMask() {
// Return the current active mask canvas which shows all chunks
// Only update if there are pending changes to avoid unnecessary redraws