Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(insertions): editing an insertion's text resizes the clip it plays
EtienneLescot0b7152a54e93
diff --git a/src/components/ai-edition/v4/EditorShellV4.module.css b/src/components/ai-edition/v4/EditorShellV4.module.cssindex 422ff0b54..c69b4277a 100644--- a/src/components/ai-edition/v4/EditorShellV4.module.css+++ b/src/components/ai-edition/v4/EditorShellV4.module.css@@ -1683,6 +1683,38 @@/* A generated clip: the media behind an inserted word, which nobody shot. Amber on the boxitself rather than a badge inside it, so it stays legible at the zoom levels where a clipis a few pixels wide and there is no room to draw anything in it. */+/* A clip a few pixels wide — an insertion of a few tenths of a second at a wide zoom is+ exactly that. Nothing fits inside it, so while it is SELECTED its controls step out to the+ right and float over whatever follows. Selection-only, so the timeline is never littered,+ and no layout above or below has to make room for them. */+.tlClipNarrow .tlClipLabel {+ display: none;+}+.tlClipSel.tlClipNarrow {+ overflow: visible;+ z-index: 6;+}+/* Selected: the pencil comes back, beside the box rather than in it, and without the name —+ which is what needed the room in the first place. */+.tlClipSel.tlClipNarrow .tlClipLabel {+ display: inline-flex;+ left: calc(100% + 6px);+ top: 50%;+ transform: translateY(-50%);+ max-width: none;+ padding: 3px 6px;+ cursor: pointer;+}+.tlClipSel.tlClipNarrow .tlClipName {+ display: none;+}+/* Clear of the pencil chip beside it. */+.tlClipDelete[data-narrow] {+ right: auto;+ left: calc(100% + 43px);+ top: 50%;+ transform: translateY(-50%);+}.tlClipGenerated {border-color: var(--warn);background: color-mix(in srgb, var(--warn) 18%, var(--surface-1));diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsxindex ba08eb74f..a4d121409 100644--- a/src/components/ai-edition/v4/V4Timeline.tsx+++ b/src/components/ai-edition/v4/V4Timeline.tsx@@ -155,6 +155,9 @@ const AUDIO_LANE_PAD_PX = 3;/** Visual separation between two clip cards. Taken off each clip's own width* (see .tlClip) rather than inserted between them, so it cannot displace the* clips that follow — which is what a flex `gap` did, once per junction. */+/** Below this a clip cannot show a label and a delete button inside itself. */+const NARROW_CLIP_PX = 120;+const CLIP_GUTTER_PX = 6;/*** Shortest region a resize may leave behind — the storage grid itself (regions@@ -2179,11 +2182,16 @@ export function V4Timeline({else if (target < from && i >= target && i < from)clipTransform = `translateX(${shiftPx}px)`;}+ // Too narrow to hold its own controls. An insertion of a few tenths+ // of a second on a half-minute timeline is a handful of pixels, and+ // there is no arrangement that fits a button inside that — so while+ // it is selected the controls step outside the box instead.+ const narrow = boxLen * pxPerSec < NARROW_CLIP_PX;return (<divkey={c.id}data-clip-id={c.id}- className={`${styles.tlClip}${+ className={`${styles.tlClip}${narrow ? ` ${styles.tlClipNarrow}` : ""}${// Amber, because nobody shot it. Same token the mark it replaces// used, so an insertion still reads as one at a glance.isGeneratedAssetId(c.assetId) ? ` ${styles.tlClipGenerated}` : ""@@ -2244,6 +2252,7 @@ export function V4Timeline({type="button"data-no-clip-dragclassName={styles.tlClipDelete}+ data-narrow={narrow ? "true" : undefined}title={t("toolbar.deleteClip")}aria-label={t("toolbar.deleteClip")}onClick={(e) => {diff --git a/src/lib/ai-edition/document/insertion.test.ts b/src/lib/ai-edition/document/insertion.test.tsindex a65ea2b27..39e430230 100644--- a/src/lib/ai-edition/document/insertion.test.ts+++ b/src/lib/ai-edition/document/insertion.test.ts@@ -8,6 +8,7 @@ import { describe, expect, it } from "vitest";import type { AxcutDocument } from "../schema";import { insertGeneratedClip, removeGeneratedClips, retextGeneratedClip } from "./insertion";import { moveClip, removeClip, resolvePlaybackSegments } from "./timeline";+import { setDocumentWordText } from "./transcript";const doc = (over: Partial<AxcutDocument> = {}): AxcutDocument =>({@@ -248,6 +249,39 @@ describe("the join is blind to what made the clips contiguous", () => {});});+describe("editing an insertion's text, through the path the pane actually calls", () => {+ it("regrows the clip and the film with it", () => {+ // The pane hands `setDocumentWordText` the SECTION's asset, which for an insertion is+ // its own `ext:` one. Its length is its text, so the edit has to reach the clip and the+ // file — a correction that left the duration alone would play the old media.+ const before = withInsertion();+ const after = setDocumentWordText(before, "ext:synth_1", "synth_1", "a much longer line");+ const seconds = "a much longer line".length / 15;+ const clip = after.timeline.clips.find((c) => c.id === "ext:synth_1");+ expect(clip?.sourceEndSec).toBeCloseTo(seconds, 6);+ expect(clip?.timelineEndSec ?? 0).toBeCloseTo((clip?.timelineStartSec ?? 0) + seconds, 6);+ // The whole film is longer by the difference, so the ruler agrees with the media.+ const end = (cs: typeof after.timeline.clips) => cs[cs.length - 1].timelineEndSec;+ expect(end(after.timeline.clips) - end(before.timeline.clips)).toBeCloseTo(+ seconds - GEN_SEC,+ 6,+ );+ });++ it("renames the file, so the save generates the media the new text needs", () => {+ const after = setDocumentWordText(withInsertion(), "ext:synth_1", "synth_1", "longer");+ expect(after.assets.find((a) => a.id === "ext:synth_1")?.originalPath).toBe(+ `C:/rec/.openscreen-extensions/synth_1_${Math.round((6 / 15) * 1000)}.mp4`,+ );+ });++ it("leaves a recorded word's correction alone — it changes no media", () => {+ const before = doc();+ const after = setDocumentWordText(before, "a1", "w1", "HELLO");+ expect(after.timeline.clips).toEqual(before.timeline.clips);+ });+});+describe("retextGeneratedClip", () => {it("resizes the clip to the new text and renames the file it plays", () => {const next = retextGeneratedClip(withInsertion(), "synth_1", "a much longer sentence");diff --git a/src/lib/ai-edition/document/insertion.ts b/src/lib/ai-edition/document/insertion.tsindex 49c2ffc66..495869b7f 100644--- a/src/lib/ai-edition/document/insertion.ts+++ b/src/lib/ai-edition/document/insertion.ts@@ -281,7 +281,15 @@ export function retextGeneratedClip(timeline: {...document.timeline,clips: resequenceClips(- document.timeline.clips.map((c) => (c.id === id ? { ...c, sourceEndSec: durationSec } : c)),+ document.timeline.clips.map((c) =>+ c.id === id+ ? // Zeroing the ruler extent is how `setClipSourceRange` asks `resequenceClips`+ // to take the clip's length from its SOURCE window. Without it the window+ // grew and the length did not: the clip kept playing the old duration and+ // the film never got longer.+ { ...c, sourceEndSec: durationSec, timelineStartSec: 0, timelineEndSec: 0 }+ : c,+ ),),},};