Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/video-editor/VideoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ export default function VideoEditor() {
borderRadius,
padding: { ...padding },
frame,
cropRegion: { ...cropRegion },
webcam: { ...webcam },
aspectRatio,
exportEncodingMode,
Expand Down Expand Up @@ -756,6 +757,7 @@ export default function VideoEditor() {
borderRadius,
padding,
frame,
cropRegion,
webcam,
aspectRatio,
exportEncodingMode,
Expand Down Expand Up @@ -848,6 +850,7 @@ export default function VideoEditor() {
setBorderRadius(snapshot.borderRadius);
setPadding({ ...snapshot.padding });
setFrame(snapshot.frame);
setCropRegion({ ...snapshot.cropRegion });
setWebcam({ ...snapshot.webcam });
setAspectRatio(snapshot.aspectRatio);
setExportEncodingMode(snapshot.exportEncodingMode);
Expand Down
32 changes: 31 additions & 1 deletion src/components/video-editor/editorPreferences.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
saveEditorPreferences,
saveEditorPresets,
} from "./editorPreferences";
import { DEFAULT_AUTO_CAPTION_SETTINGS } from "./types";
import { DEFAULT_AUTO_CAPTION_SETTINGS, DEFAULT_CROP_REGION } from "./types";

function createStorageMock(initialValues: Record<string, string> = {}): Storage {
const store = new Map(Object.entries(initialValues));
Expand Down Expand Up @@ -358,6 +358,7 @@ describe("editorPreferences", () => {
updatedAt: "2026-05-01T00:00:00.000Z",
snapshot: {
...DEFAULT_EDITOR_PREFERENCES,
cropRegion: DEFAULT_CROP_REGION,
autoCaptionSettings: DEFAULT_AUTO_CAPTION_SETTINGS,
},
},
Expand Down Expand Up @@ -385,6 +386,7 @@ describe("editorPreferences", () => {
updatedAt: "2026-05-02T00:00:00.000Z",
snapshot: {
...DEFAULT_EDITOR_PREFERENCES,
cropRegion: DEFAULT_CROP_REGION,
autoCaptionSettings: DEFAULT_AUTO_CAPTION_SETTINGS,
},
},
Expand All @@ -399,6 +401,34 @@ describe("editorPreferences", () => {
]);
});

it("preserves crop region in editor preset snapshots", () => {
const localStorage = createStorageMock();
vi.stubGlobal("localStorage", localStorage);

expect(
saveEditorPresets([
{
id: "preset-1",
name: "Cropped Demo",
createdAt: "2026-05-01T00:00:00.000Z",
updatedAt: "2026-05-01T00:00:00.000Z",
snapshot: {
...DEFAULT_EDITOR_PREFERENCES,
cropRegion: { x: 0.08, y: 0.12, width: 0.8, height: 0.7 },
autoCaptionSettings: DEFAULT_AUTO_CAPTION_SETTINGS,
},
},
]),
).toBe(true);

expect(loadEditorPresets()[0]?.snapshot.cropRegion).toEqual({
x: 0.08,
y: 0.12,
width: 0.8,
height: 0.7,
});
});

it("returns false when preset persistence fails", () => {
const localStorage = createStorageMock();
localStorage.setItem = () => {
Expand Down
10 changes: 8 additions & 2 deletions src/components/video-editor/editorPreferences.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { loadAppSetting, saveAppSetting } from "../../lib/appSettings";
import {
normalizeExportBackendPreference,
normalizeExportMp4FrameRate,
normalizeExportPipelineModel,
normalizeProjectEditor,
stripPersistedDevMotionBlurSettings,
type ProjectEditorState,
stripPersistedDevMotionBlurSettings,
} from "./projectPersistence";
import { loadAppSetting, saveAppSetting } from "../../lib/appSettings";

type PersistedEditorControls = Pick<
ProjectEditorState,
Expand Down Expand Up @@ -61,8 +61,10 @@ type PersistedEditorControls = Pick<
type PartialEditorControls = Partial<PersistedEditorControls>;

type PresetAutoCaptionSettings = ProjectEditorState["autoCaptionSettings"];
type PresetCropRegion = ProjectEditorState["cropRegion"];

export interface EditorPresetSnapshot extends PersistedEditorControls {
cropRegion: PresetCropRegion;
autoCaptionSettings: PresetAutoCaptionSettings;
whisperExecutablePath: string | null;
whisperModelPath: string | null;
Expand Down Expand Up @@ -196,9 +198,13 @@ function normalizeEditorPresetSnapshot(candidate: unknown): EditorPresetSnapshot
candidate && typeof candidate === "object"
? (candidate as Partial<EditorPresetSnapshot>)
: {};
const normalizedCropRegion = normalizeProjectEditor({
cropRegion: raw.cropRegion,
}).cropRegion;

return {
...normalizeEditorControls(normalizedPreferences, normalizedPreferences),
cropRegion: normalizedCropRegion,
autoCaptionSettings: normalizePresetAutoCaptionSettings(raw.autoCaptionSettings),
whisperExecutablePath:
normalizeNullablePath(raw.whisperExecutablePath) ??
Expand Down