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): a scrub names a moment on the ruler, not on the tape
EtienneLescot47b3fd59a86b
diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsxindex 9f6ce3930..1b1d094df 100644--- a/src/components/ai-edition/v4/V4Timeline.tsx+++ b/src/components/ai-edition/v4/V4Timeline.tsx@@ -51,6 +51,7 @@ import type { useTimeline } from "@/lib/ai-edition/store/useTimeline";import { hasAnyClipWithCamera } from "@/lib/ai-edition/timeline/camera";import { formatSec } from "@/lib/ai-edition/timeline/format";import {+ collapseRawSec,expandRawSec,type InsertedWordMark,insertedWordMarks,@@ -233,8 +234,11 @@ interface PlayheadOverlayProps {* drawn on counts the pauses, so it has to be placed through them or it drifts from* the clips by the whole added time. */inserts: readonly RulerInsert[];- /** Live scrub position, when a drag is in flight. Takes precedence over the store. */+ /** Live scrub position in RAW seconds, when a drag is in flight. */overrideTimeSec: number | null;+ /** The same drag's RULER position. Preferred when present: it is the only coordinate+ * that can name a moment INSIDE a pause, which is zero raw seconds wide. */+ overrideRulerSec: number | null;canvasStyle: React.CSSProperties;onPointerDown: (e: ReactPointerEvent) => void;playheadRef?: React.MutableRefObject<HTMLDivElement | null>;@@ -260,12 +264,17 @@ const PlayheadOverlay = memo(function PlayheadOverlay({totalSec,inserts,overrideTimeSec,+ overrideRulerSec,canvasStyle,onPointerDown,playheadRef,}: PlayheadOverlayProps) {const storeTimeSec = useProjectStore((s) => s.currentTimeSec);- const pct = (expandRawSec(overrideTimeSec ?? storeTimeSec, inserts) / totalSec) * 100;+ // The scrub hands its RULER position straight through. Expanding the raw one instead+ // would snap the playhead to a pause's left edge the moment the pointer entered it,+ // because every ruler second inside a pause collapses to the same raw moment.+ const pct =+ ((overrideRulerSec ?? expandRawSec(overrideTimeSec ?? storeTimeSec, inserts)) / totalSec) * 100;return (<div className={styles.tlPlayheadLayer} aria-hidden><div className={styles.tlCanvas} style={canvasStyle}>@@ -830,6 +839,11 @@ export function V4Timeline({// pointer for the frame the store hasn't caught up on yet. Handed down as an// override to the two components that read the playhead from the store.const [scrubbingTimeSec, setScrubbingTimeSec] = useState<number | null>(null);+ // The pointer's RULER position while scrubbing, kept apart from the raw one above.+ // Two numbers because they mean different things: the timecode reads the raw clock,+ // like the store, and the playhead has to be able to sit INSIDE a pause — which is+ // zero raw seconds wide, so no raw value can address a moment within it.+ const [scrubRulerSec, setScrubRulerSec] = useState<number | null>(null);const rafSeekRef = useRef<number>(0);const pendingSeekTimeRef = useRef<number | null>(null);@@ -846,7 +860,19 @@ export function V4Timeline({if (!el) return;const r = el.getBoundingClientRect();const pct = Math.min(1, Math.max(0, (clientX - r.left) / r.width));- const targetTime = pct * total;+ // `total` is the EXPANDED ruler, so `pct * total` is a ruler second — and+ // `setCurrentTime` is read as a RAW one by every consumer: the preview seek, the+ // caption lookup, the transcript cue, the audio mix. Writing the ruler value+ // straight in put the playhead one accumulated pause AHEAD of everything it was+ // supposed to be pointing at, which is what showed as the wrong subtitle under a+ // correctly-placed playhead (issue #560).+ //+ // Collapsing lands on the held moment when the pointer is inside a pause, which+ // is the honest answer: a pause is zero raw seconds, so there is no raw value+ // inside it to seek to. The ruler position is kept separately below so the+ // playhead still follows the pointer across it.+ const rulerTime = pct * total;+ const { sec: targetTime } = collapseRawSec(rulerTime, inserts);// Direct DOM playhead update (0ms latency, zero React re-render overhead)if (playheadElRef.current) {@@ -855,6 +881,7 @@ export function V4Timeline({// Optimistic local UI state updatesetScrubbingTimeSec(targetTime);+ setScrubRulerSec(rulerTime);pendingSeekTimeRef.current = targetTime;if (isImmediate) {@@ -876,7 +903,7 @@ export function V4Timeline({});}},- [setCurrentTime, total],+ [setCurrentTime, total, inserts],);// Mousedown anywhere on the empty timeline (ruler, lanes background, or@@ -916,6 +943,7 @@ export function V4Timeline({pendingSeekTimeRef.current = null;}setScrubbingTimeSec(null);+ setScrubRulerSec(null);};window.addEventListener("pointermove", move);window.addEventListener("pointerup", up);@@ -2418,6 +2446,7 @@ export function V4Timeline({totalSec={total}inserts={inserts}overrideTimeSec={scrubbingTimeSec}+ overrideRulerSec={scrubRulerSec}canvasStyle={canvasStyle}onPointerDown={startScrub}playheadRef={playheadElRef}diff --git a/src/lib/ai-edition/timeline/inserted-time.test.ts b/src/lib/ai-edition/timeline/inserted-time.test.tsindex 8cf37988d..509050812 100644--- a/src/lib/ai-edition/timeline/inserted-time.test.ts+++ b/src/lib/ai-edition/timeline/inserted-time.test.ts@@ -230,3 +230,37 @@ describe("insertedWordMarks", () => {expect(insertedWordMarks([{ assetId: "other", words: [synth("w1", 2)] }], split)).toEqual([]);});});++// ─── The scrub round-trip ───────────────────────────────────────────────────+// The timeline measures the pointer against the EXPANDED ruler and writes the result into+// a store every consumer reads as a RAW second — the preview seek, the caption lookup, the+// transcript cue, the audio mix. Straight through, the playhead sat one accumulated pause+// AHEAD of everything it pointed at: the right playhead, the wrong subtitle (issue #560).++describe("a scrub survives the round trip", () => {+ const marks: RulerInsert[] = [+ { id: "i1", wordId: "w1", atRawSec: 4, durationSec: 2 },+ { id: "i2", wordId: "w2", atRawSec: 9, durationSec: 1 },+ ];++ it("comes back to the raw second it started from, before and after each pause", () => {+ for (const raw of [0, 1.5, 3.9, 6, 8.5, 12, 30]) {+ expect(collapseRawSec(expandRawSec(raw, marks), marks).sec).toBeCloseTo(raw, 6);+ }+ });++ it("lands on the held moment for a pointer inside a pause, and says so", () => {+ // Every ruler second inside a pause is the same raw moment: the film is frozen+ // there, so there is nothing else it could mean.+ const inside = collapseRawSec(5, marks);+ expect(inside.sec).toBeCloseTo(4, 6);+ expect(inside.heldBy?.id).toBe("i1");+ expect(collapseRawSec(5.9, marks).sec).toBeCloseTo(4, 6);+ });++ it("counts every pause before the pointer, not just the first", () => {+ // Ruler 13 is past both: 13 − 2 − 1 = raw 10.+ expect(collapseRawSec(13, marks).sec).toBeCloseTo(10, 6);+ expect(collapseRawSec(13, marks).heldBy).toBeNull();+ });+});