From 83c45916a2b34c80c7a0f0aa9a9ff3bc5538684f Mon Sep 17 00:00:00 2001 From: Tulio Vianna Date: Wed, 19 Aug 2026 15:23:30 -0300 Subject: [PATCH] feat(editor): rebuild the clip editor around a source monitor and a working timeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Turns the clip editor into a three-point editing surface: mark in/out on the source, send the range to the clip, and scrub the result — with the timeline honest about which parts of the edit the last render can already show. - Chrome: the source track ignored drags entirely. Without preventDefault the gesture became a text selection and then a native drag, which swallows every later pointer event and shows the not-allowed cursor. - The source track's block is draggable (body moves, edges trim) and every gesture on it scrubs the source monitor, so a cut is chosen against the picture rather than against numbers. - Three-point editing: mark in / mark out (i / o) off the monitor's playhead, then "replace #N" (.) or "insert after #N" (,). Dragging empty track marks a range instead of silently appending a segment. - /edl ships the whole source transcript instead of a ±45s window: a cut can only be extended into words the editor was sent. The panel shows all of it, follows playback, and seeks the monitor on click. - Layout: source monitor + its track + transcript | clip preview + its track | controls. Each track sits under the video it drives. - The clip timeline works while edited. A cut that only removes material keeps nothing but frames the last render already produced, so it stays scrubbable and playable; only material the render never saw is marked red, and the playhead — now a solid handle — stops at its edge. Transcript words render in memoised 50-word slices: repainting a couple of thousand of them costs ~66ms, and timeupdate fires four times a second. --- app.py | 11 +- dashboard/src/components/ClipEditor.jsx | 1133 +++++++++++++++++++---- tests/test_rerender_endpoint.py | 3 +- 3 files changed, 937 insertions(+), 210 deletions(-) diff --git a/app.py b/app.py index 2874b80..209d679 100644 --- a/app.py +++ b/app.py @@ -2224,9 +2224,10 @@ async def get_clip_transcript(job_id: str, clip_index: int, request: Request): # --- Clip editor: EDL + re-render --- -# How much transcript to send around the clip's segments — enough for the -# editor's word-level trimming without shipping a whole podcast's words. -EDL_WORD_CONTEXT_SECONDS = 45.0 +# The editor ships the WHOLE source transcript, not a window around the clip: +# the point of the source track is extending a cut into material the clip never +# covered, and you cannot pick a new in-point from words you were not sent. +# Cost is about 7 KB of JSON per minute of speech, fetched once per editor open. def _source_duration_seconds(path): @@ -2295,11 +2296,9 @@ async def get_clip_edl(job_id: str, clip_index: int, request: Request): candidates.append(words[-1]['e']) source_duration = round(max(candidates), 3) - lo = min(s['start'] for s in segments) - EDL_WORD_CONTEXT_SECONDS - hi = max(s['end'] for s in segments) + EDL_WORD_CONTEXT_SECONDS words_out = [ {"w": w["w"], "s": round(w["s"], 3), "e": round(w["e"], 3)} - for w in words if w["e"] >= lo and w["s"] <= hi + for w in words ] current_file = (clip.get('video_url') or '').split('/')[-1] diff --git a/dashboard/src/components/ClipEditor.jsx b/dashboard/src/components/ClipEditor.jsx index b699b48..28a456b 100644 --- a/dashboard/src/components/ClipEditor.jsx +++ b/dashboard/src/components/ClipEditor.jsx @@ -1,7 +1,8 @@ -import React, { useState, useEffect, useReducer, useRef, useCallback, useMemo } from 'react'; +import React, { useState, useEffect, useReducer, useRef, useCallback, useMemo, useDeferredValue } from 'react'; import { X, Loader2, Plus, Trash2, ChevronUp, ChevronDown, Scissors, - AlertCircle, Undo2, Redo2, Film, + AlertCircle, Undo2, Redo2, ChevronsRight, ChevronsLeft, + PanelLeft, PanelLeftClose, Film, } from 'lucide-react'; import { getApiUrl } from '../config'; import { apiFetch, apiJson, QuotaError } from '../lib/api'; @@ -12,7 +13,16 @@ import { apiFetch, apiJson, QuotaError } from '../lib/api'; const MIN_SEGMENT_SECONDS = 0.5; const SNAP_WINDOW_SECONDS = 0.35; -const WORD_CONTEXT_SECONDS = 15; + +// Hiding the source is a working preference, not a per-clip one, so it sticks. +const HIDE_SOURCE_KEY = 'openshorts_editor_hide_source'; + +// Words per memoised transcript slice. See TranscriptChunk for why this exists. +const CHUNK_WORDS = 50; + +// Segment edges round-trip through 3 decimals, so coverage arithmetic needs a +// hair of tolerance before it calls a millisecond sliver "not rendered". +const COVERAGE_EPSILON = 0.02; const SEGMENT_COLORS = [ 'oklch(76% .17 50)', // brass @@ -104,7 +114,16 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer const [confirmClose, setConfirmClose] = useState(false); const [selectedWord, setSelectedWord] = useState(null); const [playhead, setPlayhead] = useState(0); - const [showSource, setShowSource] = useState(false); + const [showSource, setShowSource] = useState(() => { + try { return localStorage.getItem(HIDE_SOURCE_KEY) !== '1'; } catch { return true; } + }); + // Where the source monitor's playhead is, for the transcript to follow. + const [sourceTime, setSourceTime] = useState(0); + // Three-point editing, like a Premiere source monitor: mark IN and OUT on + // the source, then send that range to the clip. Kept as two independent + // numbers rather than a range so either end can be re-marked on its own. + const [markIn, setMarkIn] = useState(null); + const [markOut, setMarkOut] = useState(null); const videoRef = useRef(null); const sourceRef = useRef(null); @@ -112,6 +131,50 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer const sourceTrackRef = useRef(null); const dragRef = useRef(null); const [ghost, setGhost] = useState(null); // in-progress new segment on the source track + const transcriptRef = useRef(null); + + useEffect(() => { + try { localStorage.setItem(HIDE_SOURCE_KEY, showSource ? '0' : '1'); } catch { /* private mode */ } + }, [showSource]); + + // ---- scrubbing the source monitor --------------------------------------- + // Dragging on the source track drives this