Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(editor): update caption tabs for source-timed model

Richie McIlroy550e55ba5612
diff --git a/apps/desktop/src/routes/editor/CaptionsTab.tsx b/apps/desktop/src/routes/editor/CaptionsTab.tsx
index 17ccb6fc3..433662ff5 100644
--- a/apps/desktop/src/routes/editor/CaptionsTab.tsx
+++ b/apps/desktop/src/routes/editor/CaptionsTab.tsx
@@ -32,8 +32,10 @@ import {
DEFAULT_WHISPER_CAPTION_MODEL,
getCaptionGenerationErrorMessage,
getModelPath,
+ mapEditedTimeToSource,
PARAKEET_DIR_MODELS,
resolveCaptionModel,
+ sourceCaptionId,
supportsParakeetTranscription,
syncCaptionWordsWithText,
transcribeEditorCaptions,
@@ -160,21 +162,43 @@ export function CaptionsTab(props: {
setProject(
produce((currentProject: typeof project) => {
- const timelineSegment =
- currentProject.timeline?.captionSegments?.[index];
- if (!timelineSegment) return;
+ const timeline = currentProject.timeline;
+ const timelineSegment = timeline?.captionSegments?.[index];
+ if (!timeline || !timelineSegment) return;
+ // Apply the edit to the rendered (output-time) segment so style
+ // overrides take effect immediately and survive re-derivation.
update(timelineSegment);
- const captionSegment = currentProject.captions?.segments?.[index];
- if (!captionSegment) return;
+ // Route content/timing onto the source-time caption master so the
+ // edit persists across future clip changes. Style overrides stay on
+ // the track and are carried across by source id when re-derived.
+ const sourceId = sourceCaptionId(timelineSegment.id);
+ const source = currentProject.captions?.segments?.find(
+ (segment) => segment.id === sourceId,
+ );
+ if (!source) return;
- captionSegment.start = timelineSegment.start;
- captionSegment.end = timelineSegment.end;
- captionSegment.text = timelineSegment.text;
- captionSegment.words = timelineSegment.words?.map((word) => ({
- ...word,
- }));
+ const recordingSegments = editorInstance.recordings.segments;
+ const start = mapEditedTimeToSource(
+ timelineSegment.start,
+ timeline.segments,
+ recordingSegments,
+ );
+ const end = mapEditedTimeToSource(
+ timelineSegment.end,
+ timeline.segments,
+ recordingSegments,
+ );
+ if (start !== null) source.start = start;
+ if (end !== null) source.end = end;
+ source.text = timelineSegment.text;
+ source.words = syncCaptionWordsWithText(
+ source.text,
+ source.words,
+ source.start,
+ source.end,
+ );
}),
);
};
@@ -266,6 +290,7 @@ export function CaptionsTab(props: {
setProject("captions", {
segments: [],
settings: { ...defaultCaptionSettings },
+ sourceTimed: true,
});
}
},
diff --git a/apps/desktop/src/routes/editor/Player.tsx b/apps/desktop/src/routes/editor/Player.tsx
index 550c27e33..091977d90 100644
--- a/apps/desktop/src/routes/editor/Player.tsx
+++ b/apps/desktop/src/routes/editor/Player.tsx
@@ -12,6 +12,7 @@ import { captionsStore } from "~/store/captions";
import { commands } from "~/utils/tauri";
import AspectRatioSelect from "./AspectRatioSelect";
import { CaptionOverlay } from "./CaptionOverlay";
+import { CaptionsRegenerateBadge } from "./CaptionsRegenerateBadge";
import { createCaptionTrackSegments } from "./captions";
import {
type EditorPreviewQuality,
@@ -80,6 +81,7 @@ export function PlayerContent() {
text: segment.text,
})),
settings: { ...captionsStore.state.settings },
+ sourceTimed: true,
};
projectDidChange = true;
}
@@ -599,6 +601,7 @@ function PreviewCanvas() {
style={{ contain: "layout style" }}
onContextMenu={handleContextMenu}
>
+ <CaptionsRegenerateBadge class="absolute top-3 right-3 z-20" />
<div
class="flex overflow-hidden absolute inset-0 justify-center items-center h-full"
style={{ visibility: hasFrame() ? "visible" : "hidden" }}