← Back to Internal system builders
See how it helps
Undo and redo history
Groups editing into meaningful reversible actions and restores selection without polluting history with interface events.
undo-redo-history
Team members using this skill
When is it useful?
Use when undo reverses too much, too little or the wrong user's changes.
What does it help you do?
- Combines continuous typing but separates distinct user commands.
- Excludes cursor moves, hover and other non-content events.
- Restores selection and invalidates redo appropriately after new edits.
Try asking this
Make typing one word a single undo step while pasting a paragraph remains a separate reversible action. Type a word, paste a paragraph and undo twice. Each action should reverse as its own meaningful unit, restoring selection and clearing redo after a new edit.
Detailed documentation
Read the skill’s original instructions, examples and checks in their authored language.
Show less
Undo/Redo & History
Use this skill when designing or debugging undo/redo stacks, transaction coalescing, history boundaries, and state restoration in visual and block editors.
Human-Meaningful Undo Units (Norman & Haverbeke)
- Coalesce Continuous Micro-Edits, Separate Distinct Actions:
- A user pressing
Cmd/Ctrl+Zexpects to undo a meaningful editing step, not a single character or intermediate drag pixel:- Continuous typing: Coalesce consecutive character insertions within a time window (e.g.,
300–500 ms) at adjacent positions into one undo group; break the group on pause, cursor jump, or block boundary change. - Drag-and-drop / Resize / Slider drag: Record the pre-drag state once on
dragStart, preview intermediate frames without pushing to history, and commit a single undoable transaction ondrop. - Composite commands: Multi-step operations (e.g., "convert block type and migrate children", "paste multi-block fragment", "duplicate section") must execute inside a single transaction or history group so one
Undoreverses the entire operation atomically.
- Continuous typing: Coalesce consecutive character insertions within a time window (e.g.,
- A user pressing
- Exclude Non-Content Events from the Undo Stack:
- Never record background or metadata-only events in the user's undo history (
addToHistory: false):- Autosave status updates, server revision acknowledgments, or dirty-flag changes.
- Viewport pan/zoom, panel collapse/expand, or selection-only changes.
- Lazy-loaded asset metadata resolution or remote presence/awareness updates.
- Never record background or metadata-only events in the user's undo history (
Selection Restoration & History Integrity
- Restore Selection Alongside Content:
- Every history entry must store both the inverse document steps and the pre-/post-transaction selection anchor so
UndoandRedoplace the user's focus and cursor back at the edited location.
- Every history entry must store both the inverse document steps and the pre-/post-transaction selection anchor so
- Clear Redo Branch Only on Genuine Content Edits:
- Navigating, selecting, copying, or autosaving after an
Undomust never wipe theRedostack; only a new history-tracked content transaction clears forward redo entries.
- Navigating, selecting, copying, or autosaving after an
- Bounded History Memory:
- Cap history depth (e.g., 100–500 groups) and store compact structural deltas/steps rather than cloning full multi-megabyte document snapshots on every keystroke.
Checklist
- Are continuous keystrokes coalesced by time/position while drag/resize gestures commit as a single undo step?
- Do composite multi-block operations undo and redo atomically in a single step?
- Are autosave responses, UI view toggles, and background sync metadata excluded from the undo stack?
- Do
UndoandRedorestore both the document structure and the corresponding cursor/block selection?
Included files 1
SKILL.md
