// CommandHistory — undo/redo stack for timeline block mutations // Supports min 50 steps. execute() clears redo stack to prevent branching corruption. export class CommandHistory { constructor(maxSteps = 50) { this.undoStack = []; this.redoStack = []; this.maxSteps = maxSteps; } execute(cmd) { cmd.execute(); this.undoStack.push(cmd); if (this.undoStack.length > this.maxSteps) this.undoStack.shift(); this.redoStack = []; // clear redo on new action (prevents branching corruption) } undo() { const cmd = this.undoStack.pop(); if (!cmd) return false; cmd.undo(); this.redoStack.push(cmd); return true; } redo() { const cmd = this.redoStack.pop(); if (!cmd) return false; cmd.execute(); this.undoStack.push(cmd); return true; } get canUndo() { return this.undoStack.length > 0; } get canRedo() { return this.redoStack.length > 0; } }