feat: implement undo/redo functionality#11
Conversation
Add undo/redo support with Cmd+Z / Ctrl+Z (undo) and Cmd+Shift+Z / Ctrl+Shift+Z (redo). - useUndoHistory hook manages a history stack with debounced grouping (500ms) for regular typing - Shortcut actions (Cmd+B, Tab, Enter, etc.) are committed as discrete undo groups immediately - Paste operations are committed as their own undo group via onPaste interception - New edits after an undo clear the redo stack (standard behavior) - Uncommitted typing is flushed to history before undo so it can be redone Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
✅ Deploy Preview for rt-ash canceled.
|
QA Review (Round 1) — CHANGES_REQUESTEDReviewer: Codex (automated) SummaryUndo/redo is partially implemented, but key PRD behaviors are not fully met: redo shortcut handling is fragile, redo clearing after undo is delayed for typed edits, and shortcut-boundary grouping is incomplete for non-paste/native edit shortcuts. Issues
|
- Normalize key comparison with .toLowerCase() so Ctrl/Cmd+Shift+Z works regardless of whether the browser emits 'z' or 'Z' - Accept both metaKey and ctrlKey as the modifier so macOS Cmd shortcuts work in all environments - Clear redo stack immediately in scheduleCommit so typing after undo disables redo before the debounce fires - Add onCut handler that commits a boundary entry, making cut its own undo group (mirrors the existing onPaste handling) - Include selection state in the commit duplicate-entry check so pre-shortcut selection is preserved for correct restoration on undo - Add tests: metaKey bindings, uppercase Z redo, immediate redo-clear after undo+new edit, selection restoration after Ctrl+B Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
QA Review (Round 2) — APPROVEDReviewer: Codex (automated) SummaryThe implementation in IssuesNo issues found. |
|
Fix conflicts and then we are good to go. |
- Resolve import conflict: combine applyLink/applyLinkPaste from main with useUndoHistory from undo/redo branch - Merge duplicate handlePaste definitions: unify link-paste handling (from main) with undo history tracking (from undo/redo branch) - Guard e.clipboardData?.getData() against missing clipboardData to fix test regression - Retain onCut handler and undo/redo keyboard shortcuts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements #7
QA Review (Round 3) — CHANGES_REQUESTEDReviewer: Codex (automated) SummaryUndo/redo core behavior is largely implemented correctly (including Cmd/Ctrl+Z, Cmd/Ctrl+Shift+Z, debounce grouping, redo clearing, and Cmd/Ctrl+B + paste coverage), but one PRD requirement is not fully met for keyboard-shortcut-driven content edits beyond explicitly handled shortcuts. Issues
|
|
Just needed a QA reset. Go again! |
Detect OS/browser editing shortcuts (deleteWordBackward, deleteWordForward, deleteSoftLine*, deleteHardLine*, deleteByDrag) via onBeforeInput and commit the pre-change state immediately, so each shortcut action forms its own undo group instead of being merged with surrounding typing via the debounce. Add tests covering Ctrl+Backspace and Ctrl+Delete word-deletion paths. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
QA Review (Round 1) — APPROVEDReviewer: Codex (automated) SummaryThe implementation satisfies the PRD for undo/redo: Cmd/Ctrl+Z and Cmd/Ctrl+Shift+Z are wired correctly, typing is grouped via 500ms debounce, shortcut-driven edits (including Cmd/Ctrl+B and paste flows) are tracked as discrete history groups, redo is cleared after new edits post-undo, and tests cover the required behaviors including selection restoration for bold undo. No blocking correctness, security, quality, or performance issues were found in the reviewed code. IssuesNo issues found. |
Summary
Add undo/redo support to the text editor using standard keyboard shortcuts, with intelligent history grouping that matches the behavior of editors like VS Code.
Changes
useUndoHistory.ts— new hook managing a history stack withcommit,scheduleCommit,undo, andredooperationsEditor.tsx— integrates undo/redo: interceptsCmd/Ctrl+ZandCmd/Ctrl+Shift+Z, wraps shortcut actions and pastes as discrete undo groups, and debounces regular typing into logical chunksEditor.undo.test.tsx— 8 tests covering undo/redo of typed chunks, multi-group navigation, mid-type undo, bold shortcut undo, paste undo, redo, and redo-stack clearingPRD Requirements
Cmd+Z/Ctrl+Zundoes the most recent history groupCmd+Shift+Z/Ctrl+Shift+Zredoes the last undone groupCmd+B(bold) and other shortcut actions are pushed as discrete undo groupsonPasteinterceptionTesting
All 40 tests pass (
npm testinpackages/editor). New tests cover each acceptance criterion using@testing-library/reactwithvi.useFakeTimers()to control debounce timing.Closes #7