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(timeline): measure the clip timecode as its tabular digits render
EtienneLescot1c145e5e5c8b
diff --git a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsxindex 4e846aefd..dec07e8b3 100644--- a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx+++ b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx@@ -521,6 +521,20 @@ describe("V4Timeline clip row", () => {expect(screen.getByText("60:15.0")).toBeInTheDocument();});+ it("counts every digit at the widest digit's width, as tabular numerals render", () => {+ // The card shows its timecode in tabular numerals, where a "1" is as wide as a "0"; canvas+ // measures proportional ones. Here "1" is a third of the other digits: measured as drawn,+ // `1:11.1` would seem to fit this ~118px card (50 + 38 + 18) and then overflow it+ // (50 + 38 + 42 once each digit takes the widest advance).+ measureText.mockImplementation((text: string) => ({+ width: [...text].reduce((w, ch) => w + ("1:.".includes(ch) ? 3 : 9), 0),+ }));+ renderTimeline([clip(0, 71.1), clip(71.1, 516)]);++ expect(screen.queryByText("1:11.1")).not.toBeInTheDocument();+ expect(screen.getByText("7:24.9")).toBeInTheDocument();+ });+it("takes the card gutter out of each clip's own width", () => {// The 6px is what separates two cards. Taken off the clip's width it stays// local to that clip; inserted between them (a flex gap) it displaced everydiff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsxindex 75a014e01..6313d3b07 100644--- a/src/components/ai-edition/v4/V4Timeline.tsx+++ b/src/components/ai-edition/v4/V4Timeline.tsx@@ -175,7 +175,12 @@ function durationTextPx(text: string): number | undefined {if (ctx === null) return undefined;const family = getComputedStyle(document.documentElement).getPropertyValue("--font-body").trim();ctx.font = `500 12px ${family || "sans-serif"}`;- return ctx.measureText(text).width;+ // `.tlClipDuration` sets tabular numerals, which canvas cannot: there, every digit takes the+ // advance of the widest one, so count each digit at that width rather than at its own.+ let digitPx = 0;+ for (const digit of "0123456789") digitPx = Math.max(digitPx, ctx.measureText(digit).width);+ const others = text.replace(/[0-9]/g, "");+ return ctx.measureText(others).width + digitPx * (text.length - others.length);}function cardFitsDuration(cardPx: number, text: string): boolean {const textPx = durationTextPx(text) ?? text.length * CLIP_LABEL_FALLBACK_CHAR_PX;