Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(desktop): mirror fullscreen text holds in editor timeline math
Richie McIlroy883003c7344b
diff --git a/apps/desktop/src/routes/editor/TranscriptPage.tsx b/apps/desktop/src/routes/editor/TranscriptPage.tsxindex dd3b7710e..6ba60d595 100644--- a/apps/desktop/src/routes/editor/TranscriptPage.tsx+++ b/apps/desktop/src/routes/editor/TranscriptPage.tsx@@ -189,6 +189,7 @@ export function TranscriptPanel() {project.timeline?.transitions ?? [],undefined,"incoming",+ project.timeline?.textSegments,) ?? outputStart;const end = start + defaultDuration;const text = "New caption";@@ -273,6 +274,7 @@ export function TranscriptPanel() {project.timeline?.transitions ?? [],undefined,"incoming",+ project.timeline?.textSegments,);if (sourceTime === null) return -1;@@ -298,6 +300,7 @@ export function TranscriptPanel() {project.timeline?.segments ?? [],recordingSegments(),project.timeline?.transitions ?? [],+ project.timeline?.textSegments,);if (outputTime === null) return;if (editorState.playing) {diff --git a/apps/desktop/src/routes/editor/captions.ts b/apps/desktop/src/routes/editor/captions.tsindex c500e4079..15b44451b 100644--- a/apps/desktop/src/routes/editor/captions.ts+++ b/apps/desktop/src/routes/editor/captions.ts@@ -12,6 +12,12 @@ import {type TimelineSegment,} from "~/utils/tauri";import { type ClipTransition, clipTimelineOffsets } from "./clip-transitions";+import type { TextSegment } from "./text";+import {+ effectiveToOutput,+ heldTimeBefore,+ holdWindows,+} from "./timeline-holds";export const DEFAULT_CAPTION_MODEL = "best";export const DEFAULT_WHISPER_CAPTION_MODEL = "small";export const DEFAULT_CAPTION_LANGUAGE = "auto";@@ -350,6 +356,7 @@ export function mapSourceTimeToEdited(timelineSegments: TimelineSegment[],recordingSegments: SegmentRecordings[],transitions: ClipTransition[] = [],+ textSegments?: readonly TextSegment[],): number | null {const mappings = buildSourceToEditedMappings(timelineSegments,@@ -358,9 +365,12 @@ export function mapSourceTimeToEdited();for (const mapping of mappings) {if (sourceTime >= mapping.sourceStart && sourceTime <= mapping.sourceEnd) {- return (+ // The mapping is in the gapless recording-flow domain; seeks need+ // output time, which includes fullscreen-text holds.+ return effectiveToOutput(+ holdWindows(textSegments),mapping.editedStart +- (sourceTime - mapping.sourceStart) / mapping.timescale+ (sourceTime - mapping.sourceStart) / mapping.timescale,);}}@@ -404,7 +414,11 @@ export function mapEditedTimeToSource(transitions: ClipTransition[] = [],sourceRange?: { start: number; end: number },overlapPreference: "outgoing" | "incoming" = "outgoing",+ textSegments?: readonly TextSegment[],): number | null {+ // Output time includes fullscreen-text holds; the mappings below live in+ // the gapless recording-flow domain.+ editedTime -= heldTimeBefore(holdWindows(textSegments), editedTime);const mappings = buildSourceToEditedMappings(timelineSegments,recordingSegments,diff --git a/apps/desktop/src/routes/editor/context.ts b/apps/desktop/src/routes/editor/context.tsindex b4aee239b..c12d244a1 100644--- a/apps/desktop/src/routes/editor/context.ts+++ b/apps/desktop/src/routes/editor/context.ts@@ -93,6 +93,11 @@ import {sceneWithShotCount,setMotion,} from "./three-d";+import {+ heldTimeBefore,+ holdWindows,+ totalHeldDuration,+} from "./timeline-holds";import {getUsedTrackCount,normalizeTrackSegments,@@ -511,6 +516,9 @@ export const [EditorContextProvider, useEditorContext] = createContextProvider(const timeline = project.timeline;if (!timeline) return;const segments = timeline.segments;+ // The click position is in held-output time; clip offsets+ // live in the gapless recording-flow domain.+ time -= heldTimeBefore(holdWindows(timeline.textSegments), time);const offsets = clipTimelineOffsets(segments,timeline.transitions ?? [],@@ -1368,7 +1376,7 @@ export const [EditorContextProvider, useEditorContext] = createContextProvider(? clipTimelineDuration(project.timeline.segments,project.timeline.transitions ?? [],- )+ ) + totalHeldDuration(holdWindows(project.timeline.textSegments)): props.editorInstance.recordingDuration;type State = {diff --git a/apps/desktop/src/routes/editor/timeline-holds.ts b/apps/desktop/src/routes/editor/timeline-holds.tsnew file mode 100644index 000000000..5c8abafc7--- /dev/null+++ b/apps/desktop/src/routes/editor/timeline-holds.ts@@ -0,0 +1,59 @@+import type { TextSegment } from "./text";++// Mirrors TimelineConfiguration::hold_windows and friends in+// crates/project/src/configuration.rs — fullscreen text segments pause the+// recording clock, inserting their duration into the output timeline. The+// frontend needs the same arithmetic for the ruler, playhead clamps, clip+// positions and output<->recording conversions.++export type HoldWindow = [number, number];++export function holdWindows(+ textSegments: readonly TextSegment[] | null | undefined,+): HoldWindow[] {+ if (!textSegments?.length) return [];+ const windows = textSegments+ .filter(+ (segment) =>+ segment.enabled !== false &&+ segment.layout === "fullscreen" &&+ segment.end > segment.start,+ )+ .map((segment): HoldWindow => [segment.start, segment.end])+ .sort((a, b) => a[0] - b[0]);+ const merged: HoldWindow[] = [];+ for (const window of windows) {+ const last = merged[merged.length - 1];+ if (last && window[0] <= last[1]) {+ last[1] = Math.max(last[1], window[1]);+ } else {+ merged.push([window[0], window[1]]);+ }+ }+ return merged;+}++export function totalHeldDuration(holds: HoldWindow[]): number {+ return holds.reduce((sum, [start, end]) => sum + (end - start), 0);+}++export function heldTimeBefore(holds: HoldWindow[], time: number): number {+ return holds.reduce(+ (sum, [start, end]) => sum + Math.max(0, Math.min(time, end) - start),+ 0,+ );+}++// Places a gapless (recording-flow) timestamp back into output time, landing+// after every hold it passed.+export function effectiveToOutput(+ holds: HoldWindow[],+ effective: number,+): number {+ let output = effective;+ for (const [start, end] of holds) {+ if (output >= start) output += end - start;+ else break;+ }+ return output;+}