Skip to content

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

feat(editor): let the user pick which shape "fill frame" fills

Etienne Lescot12e7053dc749
diff --git a/src/components/ai-edition/NewEditorShell.module.css b/src/components/ai-edition/NewEditorShell.module.css
index b5c5910d9..ea4249683 100644
--- a/src/components/ai-edition/NewEditorShell.module.css
+++ b/src/components/ai-edition/NewEditorShell.module.css
@@ -987,6 +987,13 @@
color: var(--fg-2);
margin: 4px var(--sp-4) 8px;
}
+/* Clip count riding along a shape chip — present, but never louder than the shape. */
+.tabCount {
+ margin-left: 5px;
+ opacity: 0.6;
+ font-variant-numeric: tabular-nums;
+}
+
/* Caveat under a control, when the control is true but not the whole story. */
.paneHint {
margin: -2px var(--sp-4) 8px;
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsx
index 6cae93bc3..d3c000a45 100644
--- a/src/components/ai-edition/RightPanes.tsx
+++ b/src/components/ai-edition/RightPanes.tsx
@@ -1598,10 +1598,32 @@ export function VideoEffectsPane() {
onChange={toggleFillFrame}
/>
</div>
- {frameIsFilled && clipsStillFramed > 0 ? (
- <div className={styles.paneHint} role="note">
- {ts("effects.fillFrameMixed")}
- </div>
+ {/* WHICH shape to fill is only a question when the timeline has more than one, and
+ then it is the user's to answer, not ours: picking the majority silently means a
+ project that is mostly landscape with two portrait inserts can never be made to
+ fill on the portrait ones. Each shape carries its clip count, so the trade is
+ visible — same information the ratio menu's ORIGINAL section shows. */}
+ {frameIsFilled && nativeFormats.length > 1 ? (
+ <>
+ <div className={styles.paneTabs} role="group" aria-label={ts("effects.fillFrame")}>
+ {nativeFormats.map((format) => (
+ <button
+ type="button"
+ key={format.token}
+ className={format.token === settings.aspectRatio ? styles.isActive : ""}
+ onClick={() => void set({ aspectRatio: format.token })}
+ >
+ {format.token}
+ <span className={styles.tabCount}>{format.clipCount}</span>
+ </button>
+ ))}
+ </div>
+ {clipsStillFramed > 0 ? (
+ <div className={styles.paneHint} role="note">
+ {ts("effects.fillFrameMixed")}
+ </div>
+ ) : null}
+ </>
) : null}
<div className={styles.sliderGrid}>
<SliderCell
diff --git a/src/components/ai-edition/fillFrameShapes.test.tsx b/src/components/ai-edition/fillFrameShapes.test.tsx
new file mode 100644
index 000000000..cc3ac7b1a
--- /dev/null
+++ b/src/components/ai-edition/fillFrameShapes.test.tsx
@@ -0,0 +1,115 @@
+// @vitest-environment jsdom
+// A mixed timeline is the case where "fill frame" cannot keep its promise for every clip, and
+// the answer is to let the user say WHICH shape to fill rather than picking the majority
+// silently. That choice only renders under conditions the other tests can't reach — a real
+// document, with clips of two shapes, and the frame already zeroed — so it gets its own file.
+
+import "@testing-library/jest-dom";
+import { cleanup, render, screen } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { I18nProvider } from "@/contexts/I18nContext";
+import type { AxcutDocument } from "@/lib/ai-edition/schema";
+import { createEmptyDocument } from "@/lib/ai-edition/schema";
+import { useProjectStore } from "@/lib/ai-edition/store/projectStore";
+import { VideoEffectsPane } from "./RightPanes";
+
+vi.mock("sonner", () => ({ toast: { error: vi.fn(), success: vi.fn(), info: vi.fn() } }));
+
+/** A timeline whose clips carry the given pixel shapes, one clip per entry. */
+function documentWithShapes(shapes: Array<[number, number]>): AxcutDocument {
+ const base = createEmptyDocument({ title: "T", projectId: "p1" });
+ return {
+ ...base,
+ assets: shapes.map(([width, height], i) => ({
+ id: `asset_${i}`,
+ kind: "video" as const,
+ label: `Clip ${i}`,
+ originalPath: `/tmp/clip${i}.mp4`,
+ durationSec: 10,
+ cameraTrack: null,
+ video: { width, height },
+ })),
+ timeline: {
+ ...base.timeline,
+ clips: shapes.map((_, i) => ({
+ id: `clip_${i}`,
+ assetId: `asset_${i}`,
+ sourceStartSec: 0,
+ sourceEndSec: 10,
+ timelineStartSec: i * 10,
+ timelineEndSec: (i + 1) * 10,
+ wordRefs: [],
+ origin: "user" as const,
+ reason: "",
+ })),
+ },
+ // The frame already zeroed, so the switch reads ON and the choice is live.
+ legacyEditor: {
+ padding: 0,
+ borderRadius: 0,
+ shadowIntensity: 0,
+ aspectRatio: "16:9",
+ },
+ } as unknown as AxcutDocument;
+}
+
+function mount(doc: AxcutDocument) {
+ useProjectStore.setState({ document: doc });
+ return render(
+ <I18nProvider>
+ <VideoEffectsPane />
+ </I18nProvider>,
+ );
+}
+
+beforeEach(() => {
+ useProjectStore.setState({ document: null });
+});
+afterEach(cleanup);
+
+describe("a mixed timeline gets a shape to choose, not a shape imposed", () => {
+ it("offers every distinct shape, with the clip count behind each", () => {
+ // Five landscape clips and two portrait inserts: picking the majority silently would
+ // mean the portrait ones can never be made to fill.
+ mount(
+ documentWithShapes([
+ [1920, 1080],
+ [1920, 1080],
+ [1920, 1080],
+ [1920, 1080],
+ [1920, 1080],
+ [1080, 1920],
+ [1080, 1920],
+ ]),
+ );
+
+ expect(screen.getByRole("button", { name: /16:9/ })).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: /9:16/ })).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: /16:9\s*5/ })).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: /9:16\s*2/ })).toBeInTheDocument();
+ });
+
+ it("says the other shapes still show the background", () => {
+ mount(
+ documentWithShapes([
+ [1920, 1080],
+ [1080, 1920],
+ ]),
+ );
+ expect(screen.getByRole("note")).toHaveTextContent(
+ "Clips in another shape still show the background.",
+ );
+ });
+
+ it("offers no choice when every clip is the same shape — there is nothing to arbitrate", () => {
+ mount(
+ documentWithShapes([
+ [1920, 1080],
+ [3840, 2160],
+ ]),
+ );
+ // 1920x1080 and 3840x2160 are both 16:9: one shape, so no chooser and no caveat.
+ expect(screen.queryByRole("note")).not.toBeInTheDocument();
+ expect(screen.queryByRole("group")).not.toBeInTheDocument();
+ });
+});