Restore selection together with content when undoing a deletion
Undo restores paragraph text but leaves the caret pointing to the deleted node identity. A second edit then modifies the wrong paragraph. History currently keeps an editable reference to the live tree.
- Focused work estimate
- 3h 30m + prerequisites
- Priority in the scenario
- High
- Engineering practice
- Undo semantics · Immutability · Memory bounds
Estimated field mix
- Frontend70%
- Quality engineering30%
Field percentages are editorial estimates of the ticket's engineering focus. They total 100%; they are not measured time, proficiency scores, or ownership evidence.
Pattern topics
- MementoCompare
Evaluate immutable state snapshots against inverse commands for restoring both document content and logical selection within a bounded undo history.
Review it, then add it to your workspace.
The board opens an editable draft; nothing is saved until you confirm it. Sign-in and workspace permissions apply, and Demo boards remain ephemeral.
Project context
A fictional support team edits reusable troubleshooting documents with paragraphs, links, and nested sections. The browser prototype has separate toolbar and keyboard handlers, an unreliable undo stack, and mutable shared formatting objects. Create a local editor and synthetic documents; no starter assets, rich-text engine, collaborative backend, or production service is supplied.
Setup prerequisites
- Browser events
- Immutable updates
- Accessible form controls
Preceding work
Complete these dependencies, or supply their agreed outputs before taking this ticket.
Acceptance criteria
- A history entry captures enough immutable document and selection state to restore one completed command consistently.
- Undo and redo restore content and logical selection, and a new edit after undo clears the redo branch.
- Retain at most fifty entries and disclose the boundary when older history is discarded; failed commands create no entry.
Implementation constraints
- Compare a Memento snapshot with inverse commands for this bounded editor; do not serialize focusable elements or browser event objects.
Verification to include
- Delete, undo, redo, undo, then type; verify the intended restored paragraph receives the edit.
- Mutate the live document after recording history and assert old entries remain unchanged; exercise the fifty-entry limit.
Deliverables
- Bounded undo/redo history and selection restoration tests
Rollout and recovery
Start a new local history session on the upgraded model; existing saved document content remains readable even when transient old history is discarded.
Value of the work
For the engineer: Practice relating object and state patterns to real UI behavior, including undo semantics, bounded traversal, lifecycle cleanup, and memory tradeoffs.
For the team: Review whether editor changes preserve user work, keep controls consistent, and reduce maintenance effort without concealing document corruption.
Evidence boundaries
Outcome Evidence: Tests, patches, and runbooks are requested deliverables. They become Outcome Evidence only through a qualified Mission and immutable Evidence IDs.
Ownership Evidence: Independent adaptation must be observed under a declared verification policy and cite immutable Evidence IDs. Completing a planning ticket establishes no Ownership Evidence.