Skip to content

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

fix(editor): make the output format part of a style preset again

EtienneLescot1d1c01a20af6
diff --git a/src/components/ai-edition/StylePresetsMenu.tsx b/src/components/ai-edition/StylePresetsMenu.tsx
index 8eb5b5ddf..3e5010eee 100644
--- a/src/components/ai-edition/StylePresetsMenu.tsx
+++ b/src/components/ai-edition/StylePresetsMenu.tsx
@@ -176,6 +176,12 @@ export function StylePresetsMenu() {
const current = stylePresetAppearanceFromSettings(settings);
const factory = factoryStylePresetAppearance();
+ // At most ONE row reads as active. Several entries can carry the same look — the same
+ // look saved twice under two names — and a radio group lighting two of them reads as
+ // broken. First match wins, in menu order (the built-in row leads, then the saved ones).
+ const activeId = sameStylePresetLook(factory, current)
+ ? FACTORY_STYLE_PRESET_ID
+ : (presets.find((preset) => sameStylePresetLook(preset.appearance, current))?.id ?? null);
const apply = async (appearance: StylePresetAppearance, name: string) => {
setOpen(false);
@@ -302,7 +308,7 @@ export function StylePresetsMenu() {
);
const renderUserPreset = (preset: StylePreset) => {
- const active = sameStylePresetLook(preset.appearance, current);
+ const active = activeId === preset.id;
const expanded = expandedId === preset.id;
const renaming = mode.kind === "rename" && mode.id === preset.id;
const confirmingDelete = mode.kind === "confirmDelete" && mode.id === preset.id;
@@ -408,7 +414,7 @@ export function StylePresetsMenu() {
);
};
- const factoryActive = sameStylePresetLook(factory, current);
+ const factoryActive = activeId === FACTORY_STYLE_PRESET_ID;
return (
<Popover open={open} onOpenChange={onOpenChange}>
diff --git a/src/components/ai-edition/v4/EditorTopBar.stylePresets.test.tsx b/src/components/ai-edition/v4/EditorTopBar.stylePresets.test.tsx
index 18b7e76c1..199d70aa2 100644
--- a/src/components/ai-edition/v4/EditorTopBar.stylePresets.test.tsx
+++ b/src/components/ai-edition/v4/EditorTopBar.stylePresets.test.tsx
@@ -233,6 +233,17 @@ describe("Presets menu in the editor top bar", () => {
);
});
+ it("checks exactly one row when two saved presets share a look", async () => {
+ state.presets.list = vi.fn<Fn>(async () => [WARM, { ...WARM, id: "Twin", name: "Twin" }]);
+ state.settings = { ...DEFAULT_EDITOR_SETTINGS, padding: 42, wallpaper: "#aa5500" };
+ renderPane();
+ const menu = await openMenu();
+ const checked = within(menu)
+ .getAllByRole("menuitemradio")
+ .filter((row) => row.getAttribute("aria-checked") === "true");
+ expect(checked.map((row) => row.textContent)).toEqual(["Warm"]);
+ });
+
it("opens a row's actions from “⋯” without applying the preset", async () => {
renderPane();
await openMenu();
diff --git a/src/lib/ai-edition/stylePresetsEditor.test.ts b/src/lib/ai-edition/stylePresetsEditor.test.ts
index 0308dc39f..3050e3b6a 100644
--- a/src/lib/ai-edition/stylePresetsEditor.test.ts
+++ b/src/lib/ai-edition/stylePresetsEditor.test.ts
@@ -97,30 +97,27 @@ describe("stylePresetsEditor", () => {
const after = getEditorSettings(patchEditorSettings(base, stylePresetPatch(appearance)));
- // Everything but the format: the preset is 9:16, the project keeps its own.
- expect(stylePresetAppearanceFromSettings(after)).toEqual({
- ...appearance,
- aspectRatio: before.aspectRatio,
- });
- expect(after.aspectRatio).toBe(DEFAULT_EDITOR_SETTINGS.aspectRatio);
+ // The whole look, the format included — and nothing footage-dependent moved.
+ expect(stylePresetAppearanceFromSettings(after)).toEqual(appearance);
for (const key of EXCLUDED_KEYS) {
expect(after[key]).toEqual(before[key]);
}
});
- it("never changes the project's format", () => {
+ it("restores the format the preset was saved at", () => {
const vertical = patchEditorSettings(createEmptyDocument({ projectId: "p", title: "V" }), {
aspectRatio: "9:16",
});
const patch = stylePresetPatch({ ...factoryStylePresetAppearance(), aspectRatio: "16:9" });
- expect(patch).not.toHaveProperty("aspectRatio");
- expect(getEditorSettings(patchEditorSettings(vertical, patch)).aspectRatio).toBe("9:16");
+ expect(patch.aspectRatio).toBe("16:9");
+ expect(getEditorSettings(patchEditorSettings(vertical, patch)).aspectRatio).toBe("16:9");
});
- it("marks a preset active whatever the project's format", () => {
+ it("tells two looks apart by their format alone", () => {
const look = stylePresetAppearanceFromSettings(styledSettings());
- expect(sameStylePresetLook(look, { ...look, aspectRatio: "1:1" })).toBe(true);
+ expect(sameStylePresetLook(look, { ...look, aspectRatio: "1:1" })).toBe(false);
expect(sameStylePresetLook(look, { ...look, padding: look.padding + 1 })).toBe(false);
+ expect(sameStylePresetLook(look, { ...look })).toBe(true);
// Key order is irrelevant: a preset read from disk carries its keys in file order.
const reordered = Object.fromEntries(Object.entries(look).reverse()) as typeof look;
expect(sameStylePresetLook(look, reordered)).toBe(true);
diff --git a/src/lib/ai-edition/stylePresetsEditor.ts b/src/lib/ai-edition/stylePresetsEditor.ts
index f15c27e8a..189b7b972 100644
--- a/src/lib/ai-edition/stylePresetsEditor.ts
+++ b/src/lib/ai-edition/stylePresetsEditor.ts
@@ -49,10 +49,11 @@ export function stylePresetAppearanceFromSettings(
};
}
-/** Whether two appearances look the same. The format is not part of the look (see
- * `stylePresetPatch`), so a preset stays active whatever the project's ratio. */
+/** Whether two appearances look the same. The output format is part of the look: left out of
+ * this, two presets saved at different formats match at once and switching between them
+ * applies an identical patch — nothing moves, and two rows read as active. */
export function sameStylePresetLook(a: StylePresetAppearance, b: StylePresetAppearance): boolean {
- return sameValue({ ...a, aspectRatio: null }, { ...b, aspectRatio: null });
+ return sameValue(a, b);
}
/** Structural equality over plain JSON-shaped values. A preset read from disk carries its
@@ -80,8 +81,9 @@ export function factoryStylePresetAppearance(): StylePresetAppearance {
* `cursor` as `theme` and `show`. Auto-hide is written both ways (`cursor.autoHide` and
* `cursorAutoHide`) because `nextLegacy` accepts either and they land on the same key.
*
- * `aspectRatio` is left out: the format belongs to the project, so applying a look to a 9:16
- * take keeps it 9:16. The file still carries it, because format version 1 requires it.
+ * `aspectRatio` travels with the look: a preset saved at 16:9 restores 16:9, and a look is
+ * only ever active at the one format it was saved at. `aspectRatio` stays out of what a NEW
+ * project takes from a preset (`stylePresetLegacyEditor`) — the format belongs to the take.
*/
export function stylePresetPatch(appearance: StylePresetAppearance): EditorSettingsPatch {
return {
@@ -89,6 +91,7 @@ export function stylePresetPatch(appearance: StylePresetAppearance): EditorSetti
wallpaperMotion: appearance.wallpaperMotion,
frame: appearance.frame,
frameTheme: appearance.frameTheme,
+ aspectRatio: appearance.aspectRatio,
shadowIntensity: appearance.shadowIntensity,
backgroundBlur: appearance.backgroundBlur,
motionBlurAmount: appearance.motionBlurAmount,