fix(editor): four UX corrections from issue #73
- The clip track's scale is now the rendered length instead of the current total, so trimming a segment visibly shortens its bar; before, a single-segment clip always filled 100% of the track and dragging its handle appeared to move nothing. - Playback boundaries are enforced by a per-frame rAF loop instead of timeupdate (~4Hz), which let the preview overshoot a trimmed endpoint by up to 250ms — the exact frame is what an end trim is judged against. Hitting an edge also snaps currentTime back onto it. - The transcript header now offers 'segment starts/ends here' actions on the selected word, where the eye already is when choosing a cut point from the text. - Closing the editor mid-render is allowed and explained: the request keeps running and onRerendered (functional setState in App) updates the clip card after the editor is gone.
This commit is contained in:
parent
730f7de949
commit
9d18520c2e
1 changed files with 96 additions and 28 deletions
|
|
@ -618,38 +618,62 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer
|
||||||
|
|
||||||
// Walk the assembly while the file plays. Everything covered 1:1 (nothing
|
// Walk the assembly while the file plays. Everything covered 1:1 (nothing
|
||||||
// pending) short-circuits to the old behaviour: no jumps, no bookkeeping.
|
// pending) short-circuits to the old behaviour: no jumps, no bookkeeping.
|
||||||
const onClipTimeUpdate = useCallback((e) => {
|
// Reaching a boundary the file cannot cross snaps currentTime BACK onto it:
|
||||||
|
// the frame left on screen is the endpoint itself, not the overshoot.
|
||||||
|
const stepPlayback = useCallback((v) => {
|
||||||
if (dragRef.current?.kind === 'scrub') return; // seeks report a frame late
|
if (dragRef.current?.kind === 'scrub') return; // seeks report a frame late
|
||||||
const v = e.target;
|
|
||||||
if (!dirty) { setPlayhead(v.currentTime); return; }
|
if (!dirty) { setPlayhead(v.currentTime); return; }
|
||||||
|
|
||||||
let i = playSpanRef.current;
|
let i = playSpanRef.current;
|
||||||
let sp = coverage[i];
|
let sp = coverage[i];
|
||||||
if (!sp) return;
|
if (!sp) return;
|
||||||
|
|
||||||
if (sp.rendered !== null) {
|
const spEnd = sp.rendered !== null ? sp.rendered + (sp.end - sp.start) : null;
|
||||||
const spEnd = sp.rendered + (sp.end - sp.start);
|
if (spEnd !== null && v.currentTime < spEnd - COVERAGE_EPSILON) {
|
||||||
if (v.currentTime < spEnd - COVERAGE_EPSILON) {
|
|
||||||
setPlayhead(sp.start + (v.currentTime - sp.rendered));
|
setPlayhead(sp.start + (v.currentTime - sp.rendered));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Past the end of this span: move on to the next one.
|
// Past the end of this span: move on to the next one.
|
||||||
i += 1;
|
i += 1;
|
||||||
sp = coverage[i];
|
const next = coverage[i];
|
||||||
if (!sp) { v.pause(); setPlayhead(totalOf(segments)); return; }
|
if (!next || next.rendered === null) {
|
||||||
playSpanRef.current = i;
|
// Nothing to show past this edge until it is rendered, so stop ON
|
||||||
setPlayhead(sp.start);
|
// the edge rather than pretending.
|
||||||
if (sp.rendered === null) {
|
|
||||||
// Nothing to show here until it is rendered, so stop at the edge
|
|
||||||
// rather than pretending.
|
|
||||||
v.pause();
|
v.pause();
|
||||||
|
if (spEnd !== null) { try { v.currentTime = spEnd; } catch { /* not seekable yet */ } }
|
||||||
|
setPlayhead(next ? next.start : totalOf(segments));
|
||||||
|
if (next) playSpanRef.current = i;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try { v.currentTime = sp.rendered; } catch { /* not seekable yet */ }
|
playSpanRef.current = i;
|
||||||
|
setPlayhead(next.start);
|
||||||
|
try { v.currentTime = next.rendered; } catch { /* not seekable yet */ }
|
||||||
}, [coverage, dirty, segments]);
|
}, [coverage, dirty, segments]);
|
||||||
|
|
||||||
|
const onClipTimeUpdate = useCallback((e) => stepPlayback(e.target), [stepPlayback]);
|
||||||
|
|
||||||
|
// timeupdate fires ~4 times a second, which let playback overshoot a
|
||||||
|
// trimmed endpoint by up to a quarter of a second before pausing — the
|
||||||
|
// exact boundary is what an end trim is being judged against (issue #73).
|
||||||
|
// While the file plays, this loop enforces it every frame instead.
|
||||||
|
const playRafRef = useRef(0);
|
||||||
|
const stopPlayLoop = useCallback(() => {
|
||||||
|
if (playRafRef.current) cancelAnimationFrame(playRafRef.current);
|
||||||
|
playRafRef.current = 0;
|
||||||
|
}, []);
|
||||||
|
const startPlayLoop = useCallback(() => {
|
||||||
|
stopPlayLoop();
|
||||||
|
const tick = () => {
|
||||||
|
const v = videoRef.current;
|
||||||
|
if (!v || v.paused || v.ended) { playRafRef.current = 0; return; }
|
||||||
|
stepPlayback(v);
|
||||||
|
playRafRef.current = requestAnimationFrame(tick);
|
||||||
|
};
|
||||||
|
playRafRef.current = requestAnimationFrame(tick);
|
||||||
|
}, [stepPlayback, stopPlayLoop]);
|
||||||
|
useEffect(() => stopPlayLoop, [stopPlayLoop]);
|
||||||
|
|
||||||
// The native controls scrub the FILE; bring that back onto the clip.
|
// The native controls scrub the FILE; bring that back onto the clip.
|
||||||
const onClipSeeked = useCallback((e) => {
|
const onClipSeeked = useCallback((e) => {
|
||||||
if (!dirty || dragRef.current?.kind === 'scrub') return;
|
if (!dirty || dragRef.current?.kind === 'scrub') return;
|
||||||
|
|
@ -661,10 +685,12 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer
|
||||||
|
|
||||||
// Refuse to roll from a span the file cannot show — same reason as above.
|
// Refuse to roll from a span the file cannot show — same reason as above.
|
||||||
const onClipPlay = useCallback((e) => {
|
const onClipPlay = useCallback((e) => {
|
||||||
if (!dirty) return;
|
if (dirty) {
|
||||||
const sp = coverage[playSpanRef.current];
|
const sp = coverage[playSpanRef.current];
|
||||||
if (sp && sp.rendered === null) e.target.pause();
|
if (sp && sp.rendered === null) { e.target.pause(); return; }
|
||||||
}, [coverage, dirty]);
|
}
|
||||||
|
startPlayLoop();
|
||||||
|
}, [coverage, dirty, startPlayLoop]);
|
||||||
|
|
||||||
const onScrubMove = useCallback((e) => {
|
const onScrubMove = useCallback((e) => {
|
||||||
const d = dragRef.current;
|
const d = dragRef.current;
|
||||||
|
|
@ -688,8 +714,10 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try { e.currentTarget.setPointerCapture?.(e.pointerId); } catch { /* window listeners still fire */ }
|
try { e.currentTarget.setPointerCapture?.(e.pointerId); } catch { /* window listeners still fire */ }
|
||||||
|
|
||||||
|
// The track can be longer than the clip (its scale is the rendered
|
||||||
|
// length), so positions clamp to the clip's own end, not the track's.
|
||||||
const at = (clientX) => Math.max(0, Math.min(
|
const at = (clientX) => Math.max(0, Math.min(
|
||||||
clipTrackSeconds, ((clientX - rect.left) / rect.width) * clipTrackSeconds));
|
total, ((clientX - rect.left) / rect.width) * clipTrackSeconds));
|
||||||
// Direction of travel decides which wall a red span stops you at, so it
|
// Direction of travel decides which wall a red span stops you at, so it
|
||||||
// has to be the last APPLIED position, not the one at pointerdown.
|
// has to be the last APPLIED position, not the one at pointerdown.
|
||||||
let last = playhead;
|
let last = playhead;
|
||||||
|
|
@ -762,7 +790,11 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer
|
||||||
const typing = tag === 'input' || tag === 'textarea' || tag === 'select';
|
const typing = tag === 'input' || tag === 'textarea' || tag === 'select';
|
||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (dirty) setConfirmClose(true); else onClose();
|
// Leaving mid-render abandons nothing: the request keeps
|
||||||
|
// running and onRerendered updates the card when it lands.
|
||||||
|
if (rendering) onClose();
|
||||||
|
else if (dirty) setConfirmClose(true);
|
||||||
|
else onClose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (typing) return;
|
if (typing) return;
|
||||||
|
|
@ -935,7 +967,12 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const clipTrackSeconds = Math.max(total, 0.001);
|
// The track's scale is the RENDERED length (or the current total, whichever
|
||||||
|
// is longer), not the current total: normalising to the total made a
|
||||||
|
// single-segment clip fill 100% of the track no matter how it was trimmed,
|
||||||
|
// so dragging its handle visibly moved nothing (issue #73). Against the
|
||||||
|
// rendered length, shortening the clip shortens the bar.
|
||||||
|
const clipTrackSeconds = Math.max(total, totalOf(renderedSegments || []), 0.001);
|
||||||
let runningOffset = 0;
|
let runningOffset = 0;
|
||||||
const blocks = segments.map((s, i) => {
|
const blocks = segments.map((s, i) => {
|
||||||
const left = (runningOffset / clipTrackSeconds) * 100;
|
const left = (runningOffset / clipTrackSeconds) * 100;
|
||||||
|
|
@ -1086,7 +1123,7 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
onClick={() => (dirty ? setConfirmClose(true) : onClose())}
|
onClick={() => (rendering ? onClose() : dirty ? setConfirmClose(true) : onClose())}
|
||||||
className="p-2 rounded-input text-muted hover:text-ink hover:bg-paper3 transition-colors"
|
className="p-2 rounded-input text-muted hover:text-ink hover:bg-paper3 transition-colors"
|
||||||
aria-label="close editor"
|
aria-label="close editor"
|
||||||
>
|
>
|
||||||
|
|
@ -1177,9 +1214,31 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer
|
||||||
|
|
||||||
{/* transcript of the whole source */}
|
{/* transcript of the whole source */}
|
||||||
<div className="shrink-0 h-[30%] min-h-[9rem] flex flex-col">
|
<div className="shrink-0 h-[30%] min-h-[9rem] flex flex-col">
|
||||||
<div className="flex items-baseline justify-between mb-1.5 gap-2 shrink-0">
|
<div className="flex items-center justify-between mb-1.5 gap-2 shrink-0">
|
||||||
<p className="eyebrow">Transcript · full source</p>
|
<p className="eyebrow">Transcript · full source</p>
|
||||||
<span className="readout shrink-0">CLICK A WORD TO GO THERE</span>
|
{/* Boundary actions live HERE, above the words they
|
||||||
|
act on, because this is where the eye is when
|
||||||
|
picking a cut point from the text (issue #73). */}
|
||||||
|
{selectedWord ? (
|
||||||
|
<div className="flex items-center gap-1.5 shrink-0">
|
||||||
|
<button
|
||||||
|
onClick={() => setSegment(selected, { start: selectedWord.s }, { snap: false })}
|
||||||
|
title={`segment #${selected + 1} starts at "${selectedWord.w}" (${fmt(selectedWord.s)})`}
|
||||||
|
className="btn-quiet text-[11px] py-1 px-2"
|
||||||
|
>
|
||||||
|
#{selected + 1} starts here
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setSegment(selected, { end: selectedWord.e }, { snap: false })}
|
||||||
|
title={`segment #${selected + 1} ends after "${selectedWord.w}" (${fmt(selectedWord.e)})`}
|
||||||
|
className="btn-quiet text-[11px] py-1 px-2"
|
||||||
|
>
|
||||||
|
#{selected + 1} ends here
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<span className="readout shrink-0">CLICK A WORD, THEN SET A BOUNDARY</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{words.length === 0 ? (
|
{words.length === 0 ? (
|
||||||
<p className="text-xs text-muted lowercase">this job kept no transcript</p>
|
<p className="text-xs text-muted lowercase">this job kept no transcript</p>
|
||||||
|
|
@ -1249,6 +1308,7 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer
|
||||||
onTimeUpdate={onClipTimeUpdate}
|
onTimeUpdate={onClipTimeUpdate}
|
||||||
onSeeked={onClipSeeked}
|
onSeeked={onClipSeeked}
|
||||||
onPlay={onClipPlay}
|
onPlay={onClipPlay}
|
||||||
|
onPause={stopPlayLoop}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -1478,8 +1538,11 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<button className="btn-ghost" onClick={() => (dirty ? setConfirmClose(true) : onClose())}>
|
<button
|
||||||
{dirty ? 'cancel' : 'close'}
|
className="btn-ghost"
|
||||||
|
onClick={() => (rendering ? onClose() : dirty ? setConfirmClose(true) : onClose())}
|
||||||
|
>
|
||||||
|
{rendering ? 'close' : dirty ? 'cancel' : 'close'}
|
||||||
</button>
|
</button>
|
||||||
<button className="btn-primary flex-1 flex items-center justify-center gap-2" disabled={!canRender || !dirty} onClick={doRender}>
|
<button className="btn-primary flex-1 flex items-center justify-center gap-2" disabled={!canRender || !dirty} onClick={doRender}>
|
||||||
{rendering
|
{rendering
|
||||||
|
|
@ -1487,6 +1550,11 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer
|
||||||
: (needsSourcePath ? 're-render from source' : 're-render clip')}
|
: (needsSourcePath ? 're-render from source' : 're-render clip')}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{rendering && (
|
||||||
|
<p className="text-[11px] text-muted mt-2 lowercase">
|
||||||
|
you can close this editor; the render keeps going and the clip card updates when it finishes
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue