Implement Undo/Redo for Canvas Operations
Problem Implement undo/redo for a canvas editor after a series of operations (move, resize, delete, group), where grouped operations undo and redo as a single unit.
Requirements
- Apply operations;
undo()reverts the last operation,redo()reapplies it. - History is bounded; grouped ops undo/redo together.
Areas to design
- Representing an operation so it can be inverted (or the prior state restored).
- The undo and redo stacks, and how a fresh operation clears the redo stack.
- Bounding history and coalescing grouped operations.
Example
- ops → undo() restores the previous state; redo() reapplies the undone op.
asked …