Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(desktop): leave text holds past the end of the clips out of the editor duration
Richie McIlroyccbbccfbbc5f
diff --git a/apps/desktop/src/routes/editor/context.ts b/apps/desktop/src/routes/editor/context.tsindex 645385066..d3c3cf33f 100644--- a/apps/desktop/src/routes/editor/context.ts+++ b/apps/desktop/src/routes/editor/context.ts@@ -1799,13 +1799,19 @@ export const [EditorContextProvider, useBaseEditorContext] =: undefined,);- const totalDuration = () =>- project.timeline- ? clipTimelineDuration(- project.timeline.segments,- project.timeline.transitions ?? [],- ) + totalHeldDuration(holdWindows(project.timeline.textSegments))- : props.editorInstance.recordingDuration;+ const totalDuration = () => {+ if (!project.timeline) return props.editorInstance.recordingDuration;+ const clipsEnd = clipTimelineDuration(+ project.timeline.segments,+ project.timeline.transitions ?? [],+ );+ return (+ clipsEnd ++ totalHeldDuration(+ holdWindows(project.timeline.textSegments, clipsEnd),+ )+ );+ };type State = {zoom: number;diff --git a/apps/desktop/src/routes/editor/timeline-holds.test.ts b/apps/desktop/src/routes/editor/timeline-holds.test.tsnew file mode 100644index 000000000..b637b6c85--- /dev/null+++ b/apps/desktop/src/routes/editor/timeline-holds.test.ts@@ -0,0 +1,36 @@+import { describe, expect, it } from "vitest";+import { holdWindows, totalHeldDuration } from "./timeline-holds";++const fullscreen = (start: number, end: number) => ({+ start,+ end,+ layout: "fullscreen" as const,+});++describe("holdWindows", () => {+ const texts = [+ fullscreen(1, 2),+ fullscreen(4.2, 5),+ fullscreen(6.4, 7.4),+ fullscreen(9, 9.5),+ ];++ it("counts every hold without the clips' end", () => {+ expect(holdWindows(texts)).toEqual([+ [1, 2],+ [4.2, 5],+ [6.4, 7.4],+ [9, 9.5],+ ]);+ });++ it("leaves out holds that start after the clips have ended", () => {+ const holds = holdWindows(texts, 3.2);+ expect(holds).toEqual([+ [1, 2],+ [4.2, 5],+ ]);+ expect(3.2 + totalHeldDuration(holds)).toBeCloseTo(5);+ expect(holdWindows(texts, 2)).toEqual([[1, 2]]);+ });+});diff --git a/apps/desktop/src/routes/editor/timeline-holds.ts b/apps/desktop/src/routes/editor/timeline-holds.tsindex c3b1de010..80e993cd5 100644--- a/apps/desktop/src/routes/editor/timeline-holds.ts+++ b/apps/desktop/src/routes/editor/timeline-holds.ts@@ -13,8 +13,12 @@ export type HoldWindow = [number, number];export type HoldSourceSegment = Pick<TextSegment, "start" | "end"> &Partial<Pick<TextSegment, "enabled" | "layout">>;+// Pass `clipsEnd` (the clips' gapless duration) to leave out holds that start+// after the clips have ended: they hold no frame and are never reached, so+// they add nothing to the timeline, as in Rust.export function holdWindows(textSegments: readonly HoldSourceSegment[] | null | undefined,+ clipsEnd?: number,): HoldWindow[] {if (!textSegments?.length) return [];const windows = textSegments@@ -35,9 +39,21 @@ export function holdWindows(merged.push([window[0], window[1]]);}}- return merged;+ if (clipsEnd === undefined) return merged;+ const reachable: HoldWindow[] = [];+ let held = 0;+ for (const window of merged) {+ if (window[0] - held > clipsEnd + CLOSING_HOLD_TOLERANCE) break;+ held += window[1] - window[0];+ reachable.push(window);+ }+ return reachable;}+// CLOSING_HOLD_TOLERANCE in configuration.rs: a hold starting this close to+// the clips' end is a closing title.+const CLOSING_HOLD_TOLERANCE = 1e-9;+export function totalHeldDuration(holds: HoldWindow[]): number {return holds.reduce((sum, [start, end]) => sum + (end - start), 0);}