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(timeline): show Clear timeline from the stored regions, not the drawn pills

EtienneLescotb2bef6be89b1
diff --git a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
index 601bd1abc..0a379524a 100644
--- a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
@@ -86,22 +86,14 @@ function clip(startSec: number, endSec: number) {
* which is what the Full Camera button is gated on. */
const NO_CAMERA_ASSET = { id: "a1", label: "rec", durationSec: TOTAL_SEC };
-/** The five edit lanes, by the `tl` member that feeds each. */
-type EditLanes = Partial<
- Record<
- "annotationRegions" | "speedRegions" | "cameraFullscreenRegions" | "zoomRegions" | "trimRanges",
- Array<Record<string, unknown>>
- >
->;
-
-/** By default one 30-minute clip carrying a single one-second annotation; `lanes` replaces
- * what any of the five edit lanes holds (an empty `annotationRegions` clears the default). */
+/** By default one 30-minute clip carrying a single one-second annotation, and a store that
+ * holds an edit region (so Clear timeline shows); `overrides` replaces any `tl` member. */
function renderTimeline(
clips = [clip(0, TOTAL_SEC)],
annotation = { id: "ann1", startMs: 10_000, endMs: 11_000 },
assets: Array<Record<string, unknown>> = [NO_CAMERA_ASSET],
onRender?: ProfilerOnRenderCallback,
- lanes: EditLanes = {},
+ overrides: Record<string, unknown> = {},
) {
const tl = {
clips,
@@ -114,7 +106,8 @@ function renderTimeline(
cameraFullscreenRegions: [],
zoomRegions: [],
trimRanges: [],
- ...lanes,
+ hasEditRegions: true,
+ ...overrides,
selection: null,
multiSelection: [],
clipSelection: null,
@@ -421,27 +414,31 @@ describe("V4Timeline create-from-toolbar", () => {
expect(durationOf(tl)).toBeCloseTo(0.25, 3);
});
- // Clear timeline (#723) exists only while one of the five edit lanes holds a region:
- // absent, never greyed out.
- const REGION_IN_LANE: Record<keyof EditLanes, Record<string, unknown>> = {
- annotationRegions: { id: "r1", startMs: 1000, endMs: 3000 },
- zoomRegions: { id: "r1", startMs: 1000, endMs: 3000, depth: 3 },
- speedRegions: { id: "r1", startMs: 1000, endMs: 3000, speed: 1.5 },
- cameraFullscreenRegions: { id: "r1", startMs: 1000, endMs: 3000 },
- trimRanges: { id: "r1", assetId: "a1", clipId: "c@0", startSec: 1, endSec: 3 },
- };
-
+ // Clear timeline (#723) follows the STORED edit regions (`tl.hasEditRegions`), never the
+ // pills the lanes draw: a trim whose clip is gone is stored, cleared, and has no pill.
+ // Absent, never greyed out, when there is nothing to clear.
const toolbarOf = () => screen.getByRole("toolbar", { name: "toolbar.timelineTools" });
const dividersIn = (toolbar: HTMLElement) =>
Array.from(toolbar.querySelectorAll("[class*=tlToolSep]"));
- it("shows no Clear timeline button while every edit lane is empty, and no divider for it", () => {
- renderTimeline(undefined, undefined, undefined, undefined, { annotationRegions: [] });
+ it("shows no Clear timeline button while the store holds no edit region, and no divider for it", () => {
+ // A pill is drawn, and the button still follows the store.
+ renderTimeline(undefined, undefined, undefined, undefined, { hasEditRegions: false });
expect(screen.queryByLabelText("buttons.clearTimeline")).not.toBeInTheDocument();
// Only the divider after the auto-enhance button: none is left dangling at the end.
expect(dividersIn(toolbarOf())).toHaveLength(1);
});
+ it("shows it for a stored region no lane draws, and one click asks the store to clear", () => {
+ const { tl } = renderTimeline(undefined, undefined, undefined, undefined, {
+ annotationRegions: [],
+ hasEditRegions: true,
+ });
+ expect(document.querySelector("[class*=lanePill]")).toBeNull();
+ fireEvent.click(screen.getByLabelText("buttons.clearTimeline"));
+ expect(tl.clearTimeline).toHaveBeenCalledTimes(1);
+ });
+
it("puts Clear timeline last, behind a divider, after the Add Full Camera button", () => {
renderTimeline();
const toolbar = toolbarOf();
@@ -457,17 +454,6 @@ describe("V4Timeline create-from-toolbar", () => {
expect(dividersIn(toolbar)).toHaveLength(2);
});
- it.each(
- Object.keys(REGION_IN_LANE) as Array<keyof EditLanes>,
- )("shows Clear timeline for a %s region alone, and one click asks the store to clear", (lane) => {
- const { tl } = renderTimeline(undefined, undefined, undefined, undefined, {
- annotationRegions: [],
- [lane]: [REGION_IN_LANE[lane]],
- });
- fireEvent.click(screen.getByLabelText("buttons.clearTimeline"));
- expect(tl.clearTimeline).toHaveBeenCalledTimes(1);
- });
-
// #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
@@ -706,11 +692,6 @@ describe("V4Timeline audio lane drag", () => {
// 900px / 1800s = 0.5 px per second, so +90px is +180s.
const secForPx = (px: number) => (px / VIEWPORT_PX) * TOTAL_SEC;
- it("does not offer Clear timeline for an audio track alone: it is content, not an edit", () => {
- renderAudio();
- expect(screen.queryByLabelText("buttons.clearTimeline")).not.toBeInTheDocument();
- });
-
it("offers both audio paths behind one toolbar button", () => {
// A mic and a music note side by side both just said "audio"; one button
// with a named menu is what tells a first-time user the two paths apart.
diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsx
index 5ac0be39f..762a2df5a 100644
--- a/src/components/ai-edition/v4/V4Timeline.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.tsx
@@ -787,16 +787,6 @@ export function V4Timeline({
sourceIds: g.ids,
}));
- // "Clear timeline" is there while any of the five edit lanes holds a pill, and only then.
- // The audio lane is not one of them: a track is content the user added, and it stays.
- const hasEditRegions =
- annPills.length +
- speedPills.length +
- trimPills.length +
- zoomPills.length +
- cameraFullscreenPills.length >
- 0;
-
// Ruler ticks are chosen from what is actually ON SCREEN, not from the clip
// length: the canvas is widened by 1/navSpan, so the same recording shows one
// label per 30s zoomed out and one per tenth of a second zoomed in. The step
@@ -2013,7 +2003,7 @@ export function V4Timeline({
clears them. Absent with its divider, not greyed out, when there is
nothing to clear. One write in the store, so one Ctrl+Z restores every
region. */}
- {hasEditRegions ? (
+ {tl.hasEditRegions ? (
<>
<span className={styles.tlToolSep} aria-hidden />
<Tooltip content={t("buttons.clearTimeline")}>
diff --git a/src/lib/ai-edition/store/useTimeline.test.ts b/src/lib/ai-edition/store/useTimeline.test.ts
index 6b3ac5302..bb99bcb1c 100644
--- a/src/lib/ai-edition/store/useTimeline.test.ts
+++ b/src/lib/ai-edition/store/useTimeline.test.ts
@@ -5,7 +5,7 @@ import { I18nProvider } from "@/contexts/I18nContext";
import { DEFAULT_TEXT_PLATE } from "../annotations/background";
import { type RegionKind, readSpeedRegions } from "../document/timeline";
import type { AxcutDocument } from "../schema";
-import { axcutSchemaVersion } from "../schema";
+import { axcutSchemaVersion, parseDocumentFile } from "../schema";
import { useProjectStore } from "./projectStore";
import { clearHistory, redo, undo } from "./undo";
import { future, past } from "./undoStack";
@@ -873,11 +873,48 @@ describe("useTimeline.clearTimeline", () => {
...noRegions,
[kind]: 1,
});
+ // What the button's visibility reads: the stored regions, the same ones it clears.
+ expect(result.current.hasEditRegions).toBe(true);
await act(async () => {
await result.current.clearTimeline();
});
expect(regionCounts(useProjectStore.getState().document)).toEqual(noRegions);
+ expect(result.current.hasEditRegions).toBe(false);
+ });
+
+ // A trim whose carrying clip is gone is stored but not drawn: `coalescedTrimGroups` drops
+ // it from the lane, and loading accepts it (no schema rule ties `clipId` to a clip). The
+ // button follows the STORED regions, or it would hide while the action still had one to clear.
+ it("counts and clears a stored trim whose clip no longer exists, though no pill shows it", async () => {
+ const orphanDoc: AxcutDocument = {
+ ...contentDoc,
+ timeline: {
+ ...contentDoc.timeline,
+ trimRanges: [
+ {
+ id: "trim_orphan",
+ assetId: "asset_1",
+ clipId: "clip_gone",
+ startSec: 1,
+ endSec: 3,
+ reason: "",
+ origin: "user",
+ },
+ ],
+ },
+ };
+ // Loading keeps it: the schema does not tie a trim's `clipId` to an existing clip.
+ expect(parseDocumentFile(orphanDoc).timeline.trimRanges).toHaveLength(1);
+ useProjectStore.setState({ document: orphanDoc });
+ const { result } = renderTimeline();
+ expect(result.current.hasEditRegions).toBe(true);
+
+ await act(async () => {
+ await result.current.clearTimeline();
+ });
+ expect(useProjectStore.getState().document?.timeline.trimRanges).toEqual([]);
+ expect(result.current.hasEditRegions).toBe(false);
});
it("clears every region kind at once and keeps clips, media, audio, captions and transcript", async () => {
@@ -954,6 +991,8 @@ describe("useTimeline.clearTimeline", () => {
it("writes nothing when the timeline holds no edit region, whatever else it holds", async () => {
const { result } = renderTimeline();
+ // Audio track, captions and clips are all there, and none of them is an edit.
+ expect(result.current.hasEditRegions).toBe(false);
await act(async () => {
await result.current.clearTimeline();
});
diff --git a/src/lib/ai-edition/store/useTimeline.ts b/src/lib/ai-edition/store/useTimeline.ts
index f4e9b1125..2b5eb6be4 100644
--- a/src/lib/ai-edition/store/useTimeline.ts
+++ b/src/lib/ai-edition/store/useTimeline.ts
@@ -1140,13 +1140,18 @@ export function useTimeline() {
// Every edit region (zoom, speed, trim, annotation, Full Camera), on every clip, in one
// write: one undo step brings them all back. Clips, media, audio tracks, captions and the
// transcript are content, not edits, and stay (see `clearEditRegions`).
+ //
+ // `hasEditRegions` counts the STORED regions, not the pills the lanes draw: a trim whose
+ // clip is gone is stored and cleared but has no pill. The toolbar button reads it too, so
+ // what shows the button and what the action clears are one count.
+ const hasEditRegions = document !== null && countEditRegions(document) > 0;
const clearTimeline = useCallback(async () => {
- if (!document || countEditRegions(document) === 0) return;
+ if (!document || !hasEditRegions) return;
if (!(await saveDocument(clearEditRegions(document), { history: true }))) return;
// Every region a selection can point at is gone. An audio track is not one of them.
if (selection && selection.kind !== "audio") setSelection(null);
setMultiSelection((prev) => prev.filter((h) => h.kind === "audio"));
- }, [document, selection, saveDocument]);
+ }, [document, hasEditRegions, selection, saveDocument]);
// Selecting a pill and selecting a clip are the SAME act — "this is the thing
// I mean" — so they cancel each other. They used to be two states that could
@@ -1647,6 +1652,7 @@ export function useTimeline() {
addCameraFullscreen,
removeRegion,
removeRegions,
+ hasEditRegions,
clearTimeline,
addAudioTrack,
addAudio,