Build Editor Snapshots

Memento pattern

Challenge 2 of Actions as ObjectsIntermediate~55 minFree

Build a text editor with undo, redo, and bounded history by learning the Memento pattern. Across five steps you will capture and restore an editor's state through opaque snapshot objects, so the history keeper can save and roll back without ever peeking inside the editor. Unlike a command-based undo that replays individual actions, this approach photographs the whole state at each save point and restores it wholesale.

5 steps

  1. 1Snapshot and restore
  2. 2Undo with a history stack
  3. 3Redo with a second stack
  4. 4Capture more than one field
  5. 5Bound the history
Start step 1