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: guard layout edits outside clip passages

EtienneLescot51d607078763
diff --git a/src/components/ai-edition/RightPanes.layout.test.tsx b/src/components/ai-edition/RightPanes.layout.test.tsx
index 33a321ca5..e81035153 100644
--- a/src/components/ai-edition/RightPanes.layout.test.tsx
+++ b/src/components/ai-edition/RightPanes.layout.test.tsx
@@ -5,7 +5,7 @@
// the saved preference is left untouched on disk and the help popover says so.
import "@testing-library/jest-dom";
-import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
+import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { I18nProvider } from "@/contexts/I18nContext";
@@ -149,6 +149,76 @@ describe("LayoutPane passage editing", () => {
});
afterEach(() => vi.restoreAllMocks());
+ it.each([
+ 0, 4, 6, 7.999,
+ ])("keeps passage editing disabled in the gap at %s", async (currentTimeSec) => {
+ const doc = seedProject(true);
+ const clip = doc.timeline.clips[0];
+ doc.timeline.clips = [
+ { ...clip, sourceEndSec: 2, timelineStartSec: 2, timelineEndSec: 4 },
+ {
+ ...clip,
+ id: "clip_2",
+ sourceStartSec: 2,
+ sourceEndSec: 6,
+ timelineStartSec: 8,
+ timelineEndSec: 12,
+ },
+ ];
+ const partitioned = addLayoutChange(doc, 8, "dual-frame");
+ useProjectStore.setState({ currentTimeSec });
+ renderLayout(partitioned);
+ for (const name of [
+ "Picture in picture",
+ "Side by side",
+ "Top / bottom",
+ "Camera only",
+ "Screen only",
+ ])
+ expect(screen.getByRole("button", { name })).toBeDisabled();
+ expect(screen.queryByText("Entire video")).not.toBeInTheDocument();
+ const user = userEvent.setup();
+ await user.click(screen.getByRole("button", { name: "Camera only" }));
+ expect(nativeBridgeClient.aiEdition.save).not.toHaveBeenCalled();
+ expect(useProjectStore.getState().document).toBe(partitioned);
+
+ act(() => useProjectStore.setState({ currentTimeSec: 8 }));
+ expect(screen.getByRole("button", { name: "Camera only" })).toBeEnabled();
+ await user.click(screen.getByRole("button", { name: "Camera only" }));
+ await waitFor(() => {
+ const saved = useProjectStore.getState().document;
+ expect(saved && layoutRuns(saved).map((r) => [r.start, r.end, r.member.preset])).toEqual([
+ [2, 4, "picture-in-picture"],
+ [8, 12, "camera-only"],
+ ]);
+ });
+ });
+
+ it("does not treat one stored passage as a global preset before its clip", async () => {
+ const doc = seedProject(true);
+ doc.timeline.clips = [
+ { ...doc.timeline.clips[0], sourceEndSec: 4, timelineStartSec: 2, timelineEndSec: 6 },
+ ];
+ doc.layoutRegions = [
+ {
+ id: "layout_only",
+ clipId: "clip_1",
+ startMs: 2000,
+ endMs: 6000,
+ sourceStartSec: 0,
+ sourceEndSec: 4,
+ preset: "dual-frame",
+ },
+ ];
+ useProjectStore.setState({ currentTimeSec: 0 });
+ renderLayout(doc);
+ const preset = screen.getByRole("button", { name: "Screen only" });
+ expect(preset).toBeDisabled();
+ await userEvent.setup().click(preset);
+ expect(nativeBridgeClient.aiEdition.save).not.toHaveBeenCalled();
+ expect(useProjectStore.getState().document).toBe(doc);
+ });
+
it.each([6, 10, 12.5])("edits only the last passage at playhead %s", async (currentTimeSec) => {
const doc = addLayoutChange(seedProject(true), 4, "dual-frame");
useProjectStore.setState({ currentTimeSec });
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsx
index ccada8808..1e0c67410 100644
--- a/src/components/ai-edition/RightPanes.tsx
+++ b/src/components/ai-edition/RightPanes.tsx
@@ -2780,7 +2780,10 @@ export function LayoutPane() {
const currentTime = useProjectStore((s) => s.currentTimeSec);
const saveDocument = useProjectStore((s) => s.saveDocument);
const runs = useMemo(() => (document ? layoutRuns(document) : []), [document]);
- const hasLayoutChanges = runs.length > 1 || Boolean(runs[0]?.member.legacyCamera);
+ const hasLayoutChanges =
+ Boolean(document?.layoutRegions?.length) ||
+ runs.length > 1 ||
+ Boolean(runs[0]?.member.legacyCamera);
const lastPassage = runs.at(-1);
const passage =
runs.find((r) => currentTime >= r.start && currentTime < r.end) ??
@@ -2873,24 +2876,26 @@ export function LayoutPane() {
<span className={styles.sectionLabelValue}>{tt(`layouts.${effectiveLayoutPreset}`)}</span>
</div>
<div className={styles.label} style={{ marginBottom: 8 }}>
- {hasLayoutChanges && passage
- ? tt("layouts.fromUntil", {
+ {!hasLayoutChanges
+ ? tt("layouts.wholeVideo")
+ : passage &&
+ tt("layouts.fromUntil", {
start: formatSec(passage.start),
end: formatSec(passage.end),
- })
- : tt("layouts.wholeVideo")}
+ })}
</div>
<LayoutPicker
iconOnly
label={ts("layout.preset")}
value={effectiveLayoutPreset}
hasCamera={passageHasCamera}
- disabled={!hasDocument}
+ disabled={!hasDocument || (hasLayoutChanges && !passage)}
onSelect={(preset) => {
if (!document) return;
- if (hasLayoutChanges && passage)
+ if (hasLayoutChanges) {
+ if (!passage) return;
void saveDocument(setLayoutPreset(document, passage.ids[0], preset), { history: true });
- else void set({ webcamLayoutPreset: preset });
+ } else void set({ webcamLayoutPreset: preset });
}}
/>
{hasLayoutChanges && !passageHasCamera ? (
diff --git a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
index 9d37a5440..93a44e143 100644
--- a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
@@ -2,7 +2,7 @@
import "@testing-library/jest-dom";
import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
import { Profiler, type ProfilerOnRenderCallback } from "react";
-import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
// The regression under test is geometric, so the environment has to have a size:
// jsdom reports 0 for every box, which would leave `pxPerSec` at 0 (the
@@ -35,11 +35,14 @@ const measureText = vi.fn((text: string) => ({ width: text.length * 6 }));
import { ShortcutsProvider } from "@/contexts/ShortcutsContext";
import type { I18nNamespace } from "@/i18n/config";
import { getAvailableLocales, translate } from "@/i18n/loader";
+import { useProjectStore } from "@/lib/ai-edition/store/projectStore";
import type { useTimeline } from "@/lib/ai-edition/store/useTimeline";
import { DEFAULT_SHORTCUTS, formatBinding } from "@/lib/shortcuts";
import { zoomTransitionMs } from "@/lib/zoomMath/constants";
import { V4Timeline } from "./V4Timeline";
+beforeEach(() => useProjectStore.setState({ currentTimeSec: 0 }));
+
beforeAll(() => {
globalThis.ResizeObserver = class {
// jsdom has none, and the width it would report is stubbed below anyway.
@@ -93,10 +96,9 @@ function clip(startSec: number, endSec: number) {
};
}
-/** The asset every clip above points at. No `cameraTrack`: this recording has no webcam,
- * which is what the Full Camera button is gated on. */
+/** The asset every clip above points at. With no camera, only screen-only is available. */
const NO_CAMERA_ASSET = { id: "a1", label: "rec", durationSec: TOTAL_SEC };
-/** The same recording, with a camera track: the Full Camera button is offered. */
+/** The same recording with a camera track: camera layout presets become available. */
const CAMERA_ASSET = {
...NO_CAMERA_ASSET,
cameraTrack: { sourcePath: "/tmp/cam.webm", startMs: 0, offsetMs: 0, visible: true },
@@ -655,10 +657,6 @@ describe("V4Timeline create-from-toolbar", () => {
expect(dividersIn(toolbar)).toHaveLength(2);
});
- // #353. A camera-fullscreen region grows the webcam overlay, so with no webcam on the
- // timeline it renders nothing in the preview and nothing in the export — the region is
- // stored and forgotten. `addCameraFullscreen` now refuses to write one; the button says
- // so before it is clicked instead of looking like it worked.
it.each([
"media",
"no-document",
@@ -689,6 +687,44 @@ describe("V4Timeline create-from-toolbar", () => {
expect(button).toHaveTextContent("");
});
+ it("only offers a layout change inside footage and closes its menu at gaps and the final end", () => {
+ renderTimeline([clip(2, 4), clip(8, 12)]);
+ const button = screen.getByRole("button", { name: "layouts.changeHere" });
+ const seek = (currentTimeSec: number) =>
+ act(() => useProjectStore.setState({ currentTimeSec }));
+ const open = () => act(() => window.dispatchEvent(new Event("openscreen:change-layout")));
+ const menu = () => screen.queryByRole("group", { name: "layouts.title" });
+ expect(button).toBeDisabled();
+ open();
+ expect(menu()).not.toBeInTheDocument();
+ seek(2);
+ expect(button).toBeEnabled();
+ fireEvent.click(button);
+ expect(menu()).toBeInTheDocument();
+ seek(3.999);
+ expect(button).toBeEnabled();
+ expect(menu()).toBeInTheDocument();
+ seek(4);
+ expect(button).toBeDisabled();
+ expect(menu()).not.toBeInTheDocument();
+ open();
+ expect(menu()).not.toBeInTheDocument();
+ seek(6);
+ expect(button).toBeDisabled();
+ seek(8);
+ expect(button).toBeEnabled();
+ expect(menu()).not.toBeInTheDocument();
+ open();
+ expect(menu()).toBeInTheDocument();
+ seek(12);
+ expect(button).toBeDisabled();
+ expect(menu()).not.toBeInTheDocument();
+ open();
+ expect(menu()).not.toBeInTheDocument();
+ seek(13);
+ expect(button).toBeDisabled();
+ });
+
it("enables layout changes as soon as a clip's asset carries one", () => {
renderTimeline(undefined, undefined, [
{
diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsx
index 6e6ea6448..79052a249 100644
--- a/src/components/ai-edition/v4/V4Timeline.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.tsx
@@ -713,7 +713,17 @@ export function V4Timeline({
const [autoEnhanceOpen, setAutoEnhanceOpen] = useState(false);
const [audioMenuOpen, setAudioMenuOpen] = useState(false);
const [layoutOpen, setLayoutOpen] = useState(false);
- const canChangeLayout = variant === "edit" && tl.hasDoc && tl.clips.length > 0;
+ // Subscribe to availability, not the time itself: the full timeline must not
+ // re-render on every playhead tick while it stays inside the same footage.
+ const canChangeLayout = useProjectStore(
+ (s) =>
+ variant === "edit" &&
+ tl.hasDoc &&
+ tl.clips.some(
+ (clip) =>
+ s.currentTimeSec >= clip.timelineStartSec && s.currentTimeSec < clip.timelineEndSec,
+ ),
+ );
useEffect(() => {
if (!canChangeLayout) {
setLayoutOpen(false);
@@ -744,11 +754,6 @@ export function V4Timeline({
: t("toolbar.smartCutsNeedsTranscript");
const clips = tl.clips;
- // A camera-fullscreen region grows the webcam overlay, so on a project with no webcam
- // it renders nothing in the preview and nothing in the export. `addCameraFullscreen`
- // refuses to write one (see useTimeline) — this makes the control say so before it is
- // clicked instead of looking like it worked. Same question, same helper as the Layout
- // pane: is a camera attached anywhere on this timeline?
// The pauses added words created, placed on the ruler. Everything below measures the
// EXPANDED ruler — stored clip geometry plus the time those pauses add — because that
// is the film's real length and the one the playhead runs along. Stored geometry is
diff --git a/technical-documentation/architecture/timeline-model.md b/technical-documentation/architecture/timeline-model.md
index c0b8e2efe..b626577f6 100644
--- a/technical-documentation/architecture/timeline-model.md
+++ b/technical-documentation/architecture/timeline-model.md
@@ -348,6 +348,12 @@ independent Full Camera pills. Moving a boundary edits both neighbours in one un
step, with no gap or overlap. Clip insertion, duplication, source-window edits and
clear-timeline use the same anchored document operations.
+The timeline's change-here button is available only within a clip's half-open
+`[start, end)` window; entering a gap or reaching the final end closes its menu.
+For a partitioned document, the Layout pane edits a resolved passage only: gaps
+disable its preset picker, while the final end resolves to the last passage.
+It never falls back to a whole-video preset write when no passage is active.
+
`buildSceneDescription` resolves both endpoints of a change per source clip. Native
`SceneLayoutRegion::sample` drives rectangle geometry, the screen's clipping weight,
reactive camera size and camera shadow with one eased progress value. The clipping