Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

Merge branch 'main' into feature/undo-redo

FabLrce6e3abb88c54
diff --cc src/components/video-editor/KeyboardShortcutsHelp.tsx
index 308fe6562,b48896fe5..b3798e189
--- a/src/components/video-editor/KeyboardShortcutsHelp.tsx
+++ b/src/components/video-editor/KeyboardShortcutsHelp.tsx
@@@ -1,87 -1,63 +1,82 @@@
- import { HelpCircle } from "lucide-react";
+ import { HelpCircle, Settings2 } from "lucide-react";
import { useState, useEffect } from "react";
import { formatShortcut } from "@/utils/platformUtils";
+ import { useShortcuts } from "@/contexts/ShortcutsContext";
+ import { formatBinding, SHORTCUT_LABELS, SHORTCUT_ACTIONS } from "@/lib/shortcuts";
export function KeyboardShortcutsHelp() {
- const [shortcuts, setShortcuts] = useState({
- delete: 'Ctrl + D',
- pan: 'Shift + Ctrl + Scroll',
- zoom: 'Ctrl + Scroll',
- undo: 'Ctrl + Z',
- redo: 'Ctrl + Shift + Z',
- redoAlt: 'Ctrl + Y',
- });
+ const { shortcuts, isMac, openConfig } = useShortcuts();
+
+ const [scrollLabels, setScrollLabels] = useState({ pan: 'Shift + Ctrl + Scroll', zoom: 'Ctrl + Scroll' });
++ const [undoRedoLabels, setUndoRedoLabels] = useState({ undo: 'Ctrl + Z', redo: 'Ctrl + Shift + Z', redoAlt: 'Ctrl + Y' });
useEffect(() => {
Promise.all([
- formatShortcut(['mod', 'D']),
formatShortcut(['shift', 'mod', 'Scroll']),
formatShortcut(['mod', 'Scroll']),
- ]).then(([pan, zoom]) => setScrollLabels({ pan, zoom }));
+ formatShortcut(['mod', 'Z']),
+ formatShortcut(['shift', 'mod', 'Z']),
+ formatShortcut(['mod', 'Y']),
- ]).then(([deleteKey, panKey, zoomKey, undoKey, redoKey, redoAltKey]) => {
- setShortcuts({
- delete: deleteKey,
- pan: panKey,
- zoom: zoomKey,
- undo: undoKey,
- redo: redoKey,
- redoAlt: redoAltKey,
- });
++ ]).then(([pan, zoom, undo, redo, redoAlt]) => {
++ setScrollLabels({ pan, zoom });
++ setUndoRedoLabels({ undo, redo, redoAlt });
+ });
}, []);
return (
<div className="relative group">
<HelpCircle className="w-4 h-4 text-slate-500 hover:text-[#34B27B] transition-colors cursor-help" />
+
<div className="absolute right-0 top-full mt-2 w-64 bg-[#09090b] border border-white/10 rounded-lg p-3 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 shadow-xl z-50">
- <div className="text-xs font-semibold text-slate-200 mb-2">Keyboard Shortcuts</div>
+ <div className="flex items-center justify-between mb-2">
+ <span className="text-xs font-semibold text-slate-200">Keyboard Shortcuts</span>
+ <button
+ type="button"
+ onClick={openConfig}
+ title="Customize shortcuts"
+ className="flex items-center gap-1 text-[10px] text-slate-500 hover:text-[#34B27B] transition-colors"
+ >
+ <Settings2 className="w-3 h-3" />
+ Customize
+ </button>
+ </div>
+
<div className="space-y-1.5 text-[10px]">
- <div className="flex items-center justify-between">
- <span className="text-slate-400">Add Zoom</span>
- <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">Z</kbd>
- </div>
- <div className="flex items-center justify-between">
- <span className="text-slate-400">Add Annotation</span>
- <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">A</kbd>
- </div>
- <div className="flex items-center justify-between">
- <span className="text-slate-400">Add Keyframe</span>
- <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">F</kbd>
- </div>
- <div className="flex items-center justify-between">
- <span className="text-slate-400">Add Trim</span>
- <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">T</kbd>
- </div>
- <div className="flex items-center justify-between">
- <span className="text-slate-400">Delete Selected</span>
- <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">{shortcuts.delete}</kbd>
- </div>
- <div className="flex items-center justify-between">
- <span className="text-slate-400">Pan Timeline</span>
- <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">{shortcuts.pan}</kbd>
- </div>
- <div className="flex items-center justify-between">
- <span className="text-slate-400">Zoom Timeline</span>
- <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">{shortcuts.zoom}</kbd>
- </div>
- <div className="flex items-center justify-between">
- <span className="text-slate-400">Pause/Play</span>
- <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">Space</kbd>
+ {SHORTCUT_ACTIONS.map((action) => (
+ <div key={action} className="flex items-center justify-between">
+ <span className="text-slate-400">{SHORTCUT_LABELS[action]}</span>
+ <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">
+ {formatBinding(shortcuts[action], isMac)}
+ </kbd>
+ </div>
+ ))}
+
+ <div className="pt-1 border-t border-white/5 mt-1">
+ <div className="flex items-center justify-between">
+ <span className="text-slate-400">Pan Timeline</span>
+ <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">{scrollLabels.pan}</kbd>
+ </div>
+ <div className="flex items-center justify-between mt-1.5">
+ <span className="text-slate-400">Zoom Timeline</span>
+ <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">{scrollLabels.zoom}</kbd>
+ </div>
+ <div className="flex items-center justify-between mt-1.5">
+ <span className="text-slate-400">Cycle Annotations</span>
+ <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">Tab</kbd>
+ </div>
</div>
+ <div className="flex items-center justify-between">
+ <span className="text-slate-400">Undo</span>
- <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">{shortcuts.undo}</kbd>
++ <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">{undoRedoLabels.undo}</kbd>
+ </div>
+ <div className="flex items-center justify-between">
+ <span className="text-slate-400">Redo</span>
+ <div className="flex items-center gap-1">
- <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">{shortcuts.redo}</kbd>
++ <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">{undoRedoLabels.redo}</kbd>
+ <span className="text-slate-600 text-[9px]">or</span>
- <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">{shortcuts.redoAlt}</kbd>
++ <kbd className="px-1 py-0.5 bg-white/5 border border-white/10 rounded text-[#34B27B] font-mono">{undoRedoLabels.redoAlt}</kbd>
+ </div>
+ </div>
</div>
</div>
</div>
diff --cc src/components/video-editor/VideoEditor.tsx
index 7e93591a3,4e0365aba..791650afb
--- a/src/components/video-editor/VideoEditor.tsx
+++ b/src/components/video-editor/VideoEditor.tsx
@@@ -25,33 -27,42 +26,42 @@@ import
type CursorTelemetryPoint,
type TrimRegion,
type AnnotationRegion,
- type CropRegion,
type FigureData,
+ type SpeedRegion,
+ type PlaybackSpeed,
} from "./types";
import { VideoExporter, GifExporter, type ExportProgress, type ExportQuality, type ExportSettings, type ExportFormat, type GifFrameRate, type GifSizePreset, GIF_SIZE_PRESETS, calculateOutputDimensions } from "@/lib/exporter";
-import { type AspectRatio, getAspectRatioValue } from "@/utils/aspectRatioUtils";
+import { getAspectRatioValue } from "@/utils/aspectRatioUtils";
import { getAssetPath } from "@/lib/assetPath";
+import { useEditorHistory, INITIAL_EDITOR_STATE } from "@/hooks/useEditorHistory";
+ import { useShortcuts } from "@/contexts/ShortcutsContext";
+ import { matchesShortcut } from "@/lib/shortcuts";
+
+ const WALLPAPER_COUNT = 18;
+ const WALLPAPER_PATHS = Array.from({ length: WALLPAPER_COUNT }, (_, i) => `/wallpapers/wallpaper${i + 1}.jpg`);
export default function VideoEditor() {
+ const { state: editorState, pushState, updateState, commitState, undo, redo } =
+ useEditorHistory(INITIAL_EDITOR_STATE);
+
+ const {
+ zoomRegions, trimRegions, annotationRegions,
+ cropRegion, wallpaper, shadowIntensity, showBlur,
+ motionBlurEnabled, borderRadius, padding, aspectRatio,
+ } = editorState;
+
+ // ── Non-undoable state
const [videoPath, setVideoPath] = useState<string | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [isPlaying, setIsPlaying] = useState(false);
const [currentTime, setCurrentTime] = useState(0);
const [duration, setDuration] = useState(0);
- const [wallpaper, setWallpaper] = useState<string>(WALLPAPER_PATHS[0]);
- const [shadowIntensity, setShadowIntensity] = useState(0);
- const [showBlur, setShowBlur] = useState(false);
- const [motionBlurEnabled, setMotionBlurEnabled] = useState(false);
- const [borderRadius, setBorderRadius] = useState(0);
- const [padding, setPadding] = useState(50);
- const [cropRegion, setCropRegion] = useState<CropRegion>(DEFAULT_CROP_REGION);
- const [zoomRegions, setZoomRegions] = useState<ZoomRegion[]>([]);
const [cursorTelemetry, setCursorTelemetry] = useState<CursorTelemetryPoint[]>([]);
const [selectedZoomId, setSelectedZoomId] = useState<string | null>(null);
- const [trimRegions, setTrimRegions] = useState<TrimRegion[]>([]);
const [selectedTrimId, setSelectedTrimId] = useState<string | null>(null);
+ const [speedRegions, setSpeedRegions] = useState<SpeedRegion[]>([]);
+ const [selectedSpeedId, setSelectedSpeedId] = useState<string | null>(null);
- const [annotationRegions, setAnnotationRegions] = useState<AnnotationRegion[]>([]);
const [selectedAnnotationId, setSelectedAnnotationId] = useState<string | null>(null);
const [isExporting, setIsExporting] = useState(false);
const [exportProgress, setExportProgress] = useState<ExportProgress | null>(null);
@@@ -66,13 -78,27 +76,16 @@@
const videoPlaybackRef = useRef<VideoPlaybackRef>(null);
const nextZoomIdRef = useRef(1);
const nextTrimIdRef = useRef(1);
+ const nextSpeedIdRef = useRef(1);
+
+ const { shortcuts, isMac } = useShortcuts();
const nextAnnotationIdRef = useRef(1);
- const nextAnnotationZIndexRef = useRef(1); // Track z-index for stacking order
+ const nextAnnotationZIndexRef = useRef(1);
const exporterRef = useRef<VideoExporter | null>(null);
- // Helper to convert file path to proper file:// URL
const toFileUrl = (filePath: string): string => {
- // Normalize path separators to forward slashes
const normalized = filePath.replace(/\\/g, '/');
-
- // Check if it's a Windows absolute path (e.g., C:/Users/...)
- if (normalized.match(/^[a-zA-Z]:/)) {
- const fileUrl = `file:///${normalized}`;
- return fileUrl;
- }
-
- // Unix-style absolute path
- const fileUrl = `file://${normalized}`;
- return fileUrl;
+ return normalized.match(/^[a-zA-Z]:/) ? `file:///${normalized}` : `file://${normalized}`;
};
const fromFileUrl = (fileUrl: string): string => {
@@@ -284,11 -332,65 +297,65 @@@
if (selectedTrimId === id) {
setSelectedTrimId(null);
}
- }, [selectedTrimId]);
+ }, [selectedTrimId, pushState]);
+ const handleSelectSpeed = useCallback((id: string | null) => {
+ setSelectedSpeedId(id);
+ if (id) {
+ setSelectedZoomId(null);
+ setSelectedTrimId(null);
+ setSelectedAnnotationId(null);
+ }
+ }, []);
+
+ const handleSpeedAdded = useCallback((span: Span) => {
+ const id = `speed-${nextSpeedIdRef.current++}`;
+ const newRegion: SpeedRegion = {
+ id,
+ startMs: Math.round(span.start),
+ endMs: Math.round(span.end),
+ speed: DEFAULT_PLAYBACK_SPEED,
+ };
+ setSpeedRegions((prev) => [...prev, newRegion]);
+ setSelectedSpeedId(id);
+ setSelectedZoomId(null);
+ setSelectedTrimId(null);
+ setSelectedAnnotationId(null);
+ }, []);
+
+ const handleSpeedSpanChange = useCallback((id: string, span: Span) => {
+ setSpeedRegions((prev) =>
+ prev.map((region) =>
+ region.id === id
+ ? {
+ ...region,
+ startMs: Math.round(span.start),
+ endMs: Math.round(span.end),
+ }
+ : region,
+ ),
+ );
+ }, []);
+
+ const handleSpeedDelete = useCallback((id: string) => {
+ setSpeedRegions((prev) => prev.filter((region) => region.id !== id));
+ if (selectedSpeedId === id) {
+ setSelectedSpeedId(null);
+ }
+ }, [selectedSpeedId]);
+
+ const handleSpeedChange = useCallback((speed: PlaybackSpeed) => {
+ if (!selectedSpeedId) return;
+ setSpeedRegions((prev) =>
+ prev.map((region) =>
+ region.id === selectedSpeedId ? { ...region, speed } : region,
+ ),
+ );
+ }, [selectedSpeedId]);
+
const handleAnnotationAdded = useCallback((span: Span) => {
const id = `annotation-${nextAnnotationIdRef.current++}`;
- const zIndex = nextAnnotationZIndexRef.current++; // Assign z-index based on creation order
+ const zIndex = nextAnnotationZIndexRef.current++;
const newRegion: AnnotationRegion = {
id,
startMs: Math.round(span.start),
@@@ -364,59 -479,71 +431,61 @@@
? { ...region, style: { ...region.style, ...style } }
: region,
),
- );
- }, []);
+ }));
+ }, [pushState]);
const handleAnnotationFigureDataChange = useCallback((id: string, figureData: FigureData) => {
- setAnnotationRegions((prev) =>
- prev.map((region) =>
- region.id === id
- ? { ...region, figureData }
- : region,
+ pushState((prev) => ({
+ annotationRegions: prev.annotationRegions.map((region) =>
+ region.id === id ? { ...region, figureData } : region,
),
- );
- }, []);
+ }));
+ }, [pushState]);
const handleAnnotationPositionChange = useCallback((id: string, position: { x: number; y: number }) => {
- setAnnotationRegions((prev) =>
- prev.map((region) =>
- region.id === id
- ? { ...region, position }
- : region,
+ pushState((prev) => ({
+ annotationRegions: prev.annotationRegions.map((region) =>
+ region.id === id ? { ...region, position } : region,
),
- );
- }, []);
+ }));
+ }, [pushState]);
const handleAnnotationSizeChange = useCallback((id: string, size: { width: number; height: number }) => {
- setAnnotationRegions((prev) =>
- prev.map((region) =>
- region.id === id
- ? { ...region, size }
- : region,
+ pushState((prev) => ({
+ annotationRegions: prev.annotationRegions.map((region) =>
+ region.id === id ? { ...region, size } : region,
),
- );
- }, []);
+ }));
+ }, [pushState]);
- // Global Tab prevention
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
- if (e.key === 'Tab') {
- // Allow tab only in inputs/textareas
- if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
- return;
- }
- e.preventDefault();
- }
+ const mod = e.ctrlKey || e.metaKey;
+ const key = e.key.toLowerCase();
+
+ if (mod && key === 'z' && !e.shiftKey) { e.preventDefault(); e.stopPropagation(); undo(); return; }
+ if (mod && (key === 'y' || (key === 'z' && e.shiftKey))) { e.preventDefault(); e.stopPropagation(); redo(); return; }
+
+ const isInput = e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement;
+
+ if (e.key === 'Tab' && !isInput) { e.preventDefault(); }
- if ((e.key === ' ' || e.code === 'Space') && !isInput) {
+ if (matchesShortcut(e, shortcuts.playPause, isMac)) {
+ // Allow space only in inputs/textareas
- if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
- return;
- }
++ if (isInput) { return; }
e.preventDefault();
-
const playback = videoPlaybackRef.current;
if (playback?.video) {
- if (playback.video.paused) {
- playback.play().catch(console.error);
- } else {
- playback.pause();
- }
+ playback.video.paused
+ ? playback.play().catch(console.error)
+ : playback.pause();
}
}
};
window.addEventListener('keydown', handleKeyDown, { capture: true });
return () => window.removeEventListener('keydown', handleKeyDown, { capture: true });
- }, [undo, redo]);
- }, [shortcuts, isMac]);
++ }, [undo, redo, shortcuts, isMac]);
useEffect(() => {
if (selectedZoomId && !zoomRegions.some((region) => region.id === selectedZoomId)) {