From 9606a508412e41b75da1f22ea4f0c3af275209ad Mon Sep 17 00:00:00 2001 From: ida-jemi Date: Sat, 20 Jun 2026 18:45:48 +0300 Subject: [PATCH] feat: add undo/redo support for editing actions - Add generic useUndoRedo hook with debounced history stack (max 25 entries) - Wire into useVideoEditor: push EditRecipe snapshots, expose undo/redo/canUndo/canRedo - Add Ctrl+Z / Ctrl+Shift+Z / Ctrl+Y keyboard shortcuts - Add Undo/Redo buttons next to Reset All Settings - Update KeyboardShortcutsPanel with new shortcuts - Add unit tests for useUndoRedo Closes #1591 --- src/components/VideoEditor.tsx | 34 +++++++- src/hooks/__tests__/useUndoRedo.test.ts | 104 ++++++++++++++++++++++++ src/hooks/useKeyboardShortcuts.ts | 23 +++++- src/hooks/useUndoRedo.ts | 98 ++++++++++++++++++++++ src/hooks/useVideoEditor.ts | 50 +++++++++++- 5 files changed, 305 insertions(+), 4 deletions(-) create mode 100644 src/hooks/__tests__/useUndoRedo.test.ts create mode 100644 src/hooks/useUndoRedo.ts diff --git a/src/components/VideoEditor.tsx b/src/components/VideoEditor.tsx index a12c1f41..88c920c7 100644 --- a/src/components/VideoEditor.tsx +++ b/src/components/VideoEditor.tsx @@ -22,7 +22,7 @@ import { getPresetById } from "@/lib/presets"; import { cn } from "@/lib/utils"; import { Layers, Crop, Scissors, RotateCw, Volume2, Type, - SlidersHorizontal, Zap, AlertTriangle, Github, Copy + SlidersHorizontal, Zap, AlertTriangle, Github, Copy, Undo2, Redo2, } from "lucide-react"; import OnboardingTour from "./OnboardingTour"; import { useKeyboardShortcuts } from "@/hooks/useKeyboardShortcuts"; @@ -153,6 +153,14 @@ function KeyboardShortcutsPanel() { keys: [?], label: "Toggle this panel", }, + { + keys: [Ctrl, +, Z], + label: "Undo", + }, + { + keys: [Ctrl, +, Shift, +, Z], + label: "Redo", + }, ]; return ( @@ -211,6 +219,7 @@ export default function VideoEditor() { recommendedPreset, currentTime, toggleSound, + undo, redo, canUndo, canRedo, } = useVideoEditor(); useKeyboardShortcuts({ @@ -222,6 +231,7 @@ export default function VideoEditor() { status, cancelExport, onToggleShortcutsModal: () => {}, + undo, redo, }); const [copied, setCopied] = useState(false); @@ -704,6 +714,28 @@ return () => {
+ +