Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(editor): size the card timecode gate to the timecode it is gating

超超超超超级喜欢你的达妮娅f5a56c01a64f
diff --git a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
index 8ab72384c..8f3320cc2 100644
--- a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
@@ -483,6 +483,17 @@ describe("V4Timeline clip row", () => {
expect(screen.getByText("25:50.0")).toBeInTheDocument();
});
+ it("asks for the room this card's own timecode needs, not the shortest one", () => {
+ // 600s of 3965s is a ~130px card. `0:12.0` would fit there; `10:00.0` is a
+ // character wider and does not, and `formatSec` has no hour field to stop
+ // the string growing — a clip past a hundred minutes reads `100:00.0`. A
+ // single fixed width would have let those through onto the delete button.
+ renderTimeline([clip(0, 600), clip(600, 3965)]);
+
+ expect(screen.queryByText("10:00.0")).not.toBeInTheDocument();
+ expect(screen.getByText("56:05.0")).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 every
diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsx
index 17d2d6bc3..bd97d7301 100644
--- a/src/components/ai-edition/v4/V4Timeline.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.tsx
@@ -151,12 +151,22 @@ const PILL_SNAP_PX = 8;
* 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;
-// A card wide enough to also carry its edited duration. The label pill is capped
-// at `calc(100% - 50px)` to clear the delete button, and its incompressible
-// content — padding, the pencil, two gaps and the timecode — is ~76px, so below
-// this the timecode escapes the pill and lands on that button. Measured in the
-// running window: overlapping at 121px, clean from 131px.
-const CLIP_DURATION_PX = 132;
+// Whether a card can also carry its edited duration. The label pill is capped at
+// `calc(100% - 50px)` so it clears the delete button, and everything inside it
+// but the name is incompressible: 15px of padding, the 16px pencil, two 8px
+// gaps, and the timecode. The timecode is the part that varies — `formatSec`
+// never prints an hour field, so a clip past ten minutes reads `16:40.0` and one
+// past a hundred `100:00.0` — so the room is measured against THIS card's own
+// text rather than a single number that only ever fitted the short form.
+// Measured in the running window: 6.0px per character at 10px in the mono face,
+// and a 6-character code overlapping the delete button at a 121px card, clear at
+// 131px.
+const CLIP_LABEL_RESERVE_PX = 50;
+const CLIP_LABEL_FIXED_PX = 47;
+const CLIP_LABEL_CHAR_PX = 6;
+function cardFitsDuration(cardPx: number, text: string): boolean {
+ return cardPx >= CLIP_LABEL_RESERVE_PX + CLIP_LABEL_FIXED_PX + text.length * CLIP_LABEL_CHAR_PX;
+}
const CLIP_GUTTER_PX = 6;
/**
@@ -2179,6 +2189,9 @@ export function V4Timeline({
// 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;
+ // The gutter is taken out of the card's own width below, so the
+ // room the label actually has is that much less than the span.
+ const durText = formatSec(dur);
return (
<div
key={c.id}
@@ -2238,8 +2251,8 @@ export function V4Timeline({
<span className={styles.tlClipName}>
{tl.assets.find((a) => a.id === c.assetId)?.label ?? c.assetId}
</span>
- {boxLen * pxPerSec >= CLIP_DURATION_PX ? (
- <span className={styles.tlClipDuration}>{formatSec(dur)}</span>
+ {cardFitsDuration(boxLen * pxPerSec - CLIP_GUTTER_PX, durText) ? (
+ <span className={styles.tlClipDuration}>{durText}</span>
) : null}
</div>
{selected ? (