An undoable command records enough information to restore its input state when applied immediately after its corresponding edit. In a sequence, insertion at index is reversed by deletion at ; deletion is reversed by reinsertion of the saved value. If a move places an entry at final index after removing it from index , the inverse moves it from back to . Removing the moved entry recovers the original sequence with exactly that entry missing, which proves the inverse for both directions and for .
These local inverse identities extend to a history by applying inverses in reverse chronological order. A stack of completed commands and a stack of undone commands maintain that order. A fresh command invalidates the old redo branch. Arbitrary inverses after unrelated intervening edits need not satisfy the restoration identity. State snapshots in the Memento pattern supply a different way to realize the same chronological undo/redo contract.

Articles by others on the same topic (0)

There are currently no matching articles.