Expand description
History stack for undo/redo operations.
This module provides the HistoryManager which maintains dual stacks
for undo and redo operations with support for:
- Memory limits: Oldest commands evicted when budget exceeded
- Depth limits: Maximum number of commands in history
- Branch handling: New actions clear the redo stack
- Command merging: Consecutive similar commands batched together
§Invariants
total_bytesalways equals sum ofsize_bytes()for all commandsundo_stack.len() <= config.max_depth(after any operation)total_bytes <= config.max_bytes(after any operation, if enforced)- Redo stack is cleared whenever a new command is pushed
§Memory Model
Commands are stored in VecDeque for O(1) eviction from the front.
Memory accounting uses each command’s size_bytes() method.
push(cmd5)
┌───────────────────────────────────────────────┐
│ Undo Stack: [cmd1, cmd2, cmd3, cmd4, cmd5] │
│ Redo Stack: [] │
└───────────────────────────────────────────────┘
undo() x2
┌───────────────────────────────────────────────┐
│ Undo Stack: [cmd1, cmd2, cmd3] │
│ Redo Stack: [cmd4, cmd5] │
└───────────────────────────────────────────────┘
push(cmd6) <-- new branch, clears redo
┌───────────────────────────────────────────────┐
│ Undo Stack: [cmd1, cmd2, cmd3, cmd6] │
│ Redo Stack: [] │
└───────────────────────────────────────────────┘Structs§
- History
Config - Configuration for the history manager.
- History
Manager - Manager for undo/redo history.