The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
feat(bin): marquee multi-select with batch delete and batch drop
Jareer136c6f040d59
diff --git a/desktop/src/App.tsx b/desktop/src/App.tsxindex 17adb292..72bb19dd 100644--- a/desktop/src/App.tsx+++ b/desktop/src/App.tsx@@ -180,7 +180,7 @@ function Editor({const [modifyingProject, setModifyingProject] = useState<null | { busy: boolean }>(null);const [selectedClipIds, setSelectedClipIds] = useState<string[]>([]);- const [selectedMediaId, setSelectedMediaId] = useState<string | null>(null);+ const [selectedMediaIds, setSelectedMediaIds] = useState<string[]>([]);const [tool, setTool] = useState<Tool>("select");const [snap, setSnap] = useState(true);const [binFilter, setBinFilter] = useState<BinFilter>(ALL_MEDIA);@@ -220,6 +220,8 @@ function Editor({// Read by event listeners that outlive the render that installed them.const latest = useRef({ project, secondsPerPixel, scrollLeft, trackScroll, snap, playhead, frame });latest.current = { project, secondsPerPixel, scrollLeft, trackScroll, snap, playhead, frame };+ const selectedMediaRef = useRef(selectedMediaIds);+ selectedMediaRef.current = selectedMediaIds;// The project's rate is authoritative, not the first clip's.const frameRate = session.frameRate;@@ -230,9 +232,10 @@ function Editor({const kept = ids.filter((id) => timeline.clips.some((clip) => clip.id === id));return kept.length === ids.length ? ids : kept;});- setSelectedMediaId((id) =>- id && project.media.some((item) => item.id === id) ? id : null,- );+ setSelectedMediaIds((ids) => {+ const kept = ids.filter((id) => project.media.some((item) => item.id === id));+ return kept.length === ids.length ? ids : kept;+ });// Keyed on the engine state, not the echo - the echo never removes clips.// eslint-disable-next-line react-hooks/exhaustive-deps}, [view]);@@ -324,7 +327,7 @@ function Editor({item: newMediaFromSummary(summary),});if (mediaId) {- setSelectedMediaId(mediaId);+ setSelectedMediaIds([mediaId]);// Fire and forget: the clip draws flat until the artwork lands.requestAssets(assets.current,@@ -399,7 +402,7 @@ function Editor({}).then((clipId) => {if (clipId) {setSelectedClipIds([clipId]);- setSelectedMediaId(null);+ setSelectedMediaIds([]);setRightTab("text");}});@@ -592,15 +595,6 @@ function Editor({);// ── edit operations ──────────────────────────────────────────────────────- const placeMedia = useCallback(- (mediaId: string, trackId: string, start: number) => {- void dispatch({ op: "addClip", mediaId, trackId, start }).then((clipId) => {- if (clipId) setSelectedClipIds([clipId]);- });- },- [dispatch],- );-const addToTimeline = useCallback((mediaId: string) => {void dispatch({@@ -614,6 +608,41 @@ function Editor({[dispatch],);+ /**+ * Places several bin items end to end from `start`, as one batch and one+ * undo step - the multi-select drop and the File menu's add-selected.+ * With a track they land on that lane; without one each finds the first+ * free lane for its own span, like a double-click does.+ */+ const placeMediaSet = useCallback(+ (mediaIds: string[], start: number, trackId: string | null) => {+ const current = latest.current.project;+ let at = Math.max(0, start);+ const commands = mediaIds.flatMap((mediaId) => {+ const media = findMedia(current, mediaId);+ if (!media) return [];+ const from = at;+ // The engine's own placement defaults (relay-project: a still lasts+ // 5s, unknown-duration media falls back to 5s) - mirrored here only+ // to lay items end to end; the engine still decides each clip's+ // real duration.+ at += media.kind === "image" ? 5 : (media.duration ?? 5);+ return [+ trackId+ ? ({ op: "addClip", mediaId, trackId, start: from } as const)+ : ({ op: "addClipAtFirstFree", mediaId, start: from } as const),+ ];+ });+ if (commands.length === 0) return;+ void dispatch(+ commands.length === 1 ? commands[0] : { op: "batch", commands: [...commands] },+ ).then((clipId) => {+ if (clipId) setSelectedClipIds([clipId]);+ });+ },+ [dispatch],+ );+const beginMediaDrag = useCallback((item: MediaItem, clientX: number, clientY: number) => {setMediaDrag({ item, x: clientX, y: clientY });@@ -643,13 +672,15 @@ function Editor({playhead: state.playhead,}): drop.start;- placeMedia(item.id, drop.trackId, Math.max(0, start));+ const set = selectedMediaRef.current;+ const dragged = set.includes(item.id) && set.length > 1 ? set : [item.id];+ placeMediaSet(dragged, Math.max(0, start), drop.trackId);};window.addEventListener("pointermove", onMove);window.addEventListener("pointerup", onUp);},- [placeMedia],+ [placeMediaSet],);const splitAtPlayhead = useCallback(() => {@@ -669,11 +700,26 @@ function Editor({});}, [selectedClipIds, dispatch]);+ /** Deletes the bin selection as one undo step; removal cascades clips. */+ const deleteSelectedMedia = useCallback(() => {+ const ids = selectedMediaRef.current;+ if (ids.length === 0) return;+ const commands = ids.map((mediaId) => ({ op: "removeMedia", mediaId }) as const);+ void dispatch(+ commands.length === 1 ? commands[0] : { op: "batch", commands: [...commands] },+ );+ setSelectedMediaIds([]);+ }, [dispatch]);+const deleteSelected = useCallback(() => {- if (selectedClipIds.length === 0) return;- void dispatch({ op: "removeClips", clipIds: selectedClipIds });- setSelectedClipIds([]);- }, [selectedClipIds, dispatch]);+ if (selectedClipIds.length > 0) {+ void dispatch({ op: "removeClips", clipIds: selectedClipIds });+ setSelectedClipIds([]);+ return;+ }+ // No clips selected: Delete acts on the bin selection instead.+ deleteSelectedMedia();+ }, [selectedClipIds, deleteSelectedMedia, dispatch]);const zoom = useCallback((factor: number, anchor?: number) => {const previous = zoomRef.current;@@ -866,8 +912,8 @@ function Editor({selectedClipIds.length === 1 ? findClip(project, selectedClipIds[0]) : null;const inspectorMedia = selectedClip? findMedia(project, selectedClip.mediaId)- : selectedMediaId- ? findMedia(project, selectedMediaId)+ : selectedMediaIds.length === 1+ ? findMedia(project, selectedMediaIds[0]): null;return (@@ -907,8 +953,8 @@ function Editor({{label: "Add selected to timeline",icon: "plus",- disabled: !selectedMediaId,- onSelect: () => selectedMediaId && addToTimeline(selectedMediaId),+ disabled: selectedMediaIds.length === 0,+ onSelect: () => placeMediaSet(selectedMediaIds, latest.current.playhead, null),},{label: "Save",@@ -1027,17 +1073,18 @@ function Editor({assets={assets.current}dropping={dropping}filter={binFilter}- selectedId={selectedMediaId}+ selectedIds={selectedMediaIds}busy={busy}error={error}onFilter={setBinFilter}onAddText={addText}- onSelect={(id) => {- setSelectedMediaId(id);- setSelectedClipIds([]);+ onSelect={(ids) => {+ setSelectedMediaIds(ids);+ if (ids.length > 0) setSelectedClipIds([]);}}onImport={(paths) => void importPaths(paths)}onRemove={(id) => void dispatch({ op: "removeMedia", mediaId: id })}+ onRemoveSelected={deleteSelectedMedia}onDismissError={() => setError(null)}onBeginDrag={beginMediaDrag}onAddToTimeline={addToTimeline}@@ -1432,6 +1479,11 @@ function Editor({className={mediaDrag.item.kind === "video" ? "text-accent" : "text-clip-audio"}/><span className="max-w-48 truncate text-xs text-primary">{mediaDrag.item.name}</span>+ {selectedMediaIds.length > 1 && selectedMediaIds.includes(mediaDrag.item.id) && (+ <span className="rounded bg-accent px-1.5 font-technical text-[10px] text-on-accent">+ {selectedMediaIds.length}+ </span>+ )}</div>)}</div>diff --git a/desktop/src/components/MediaBin.tsx b/desktop/src/components/MediaBin.tsxindex 7cb9d2ca..00e47bd1 100644--- a/desktop/src/components/MediaBin.tsx+++ b/desktop/src/components/MediaBin.tsx@@ -63,7 +63,7 @@ const TABS: { id: LibraryTab; label: string }[] = [export function MediaBin({items,filter,- selectedId,+ selectedIds,busy,error,onFilter,@@ -71,6 +71,7 @@ export function MediaBin({onSelect,onImport,onRemove,+ onRemoveSelected,onDismissError,onBeginDrag,onAddToTimeline,@@ -88,15 +89,18 @@ export function MediaBin({dropping: boolean;/** Shared with the timeline, so a waveform is only ever computed once. */assets: MediaAssets;- selectedId: string | null;+ selectedIds: readonly string[];busy: boolean;error: string | null;onFilter: (filter: BinFilter) => void;/** Puts a new title on the timeline at the playhead. */onAddText: () => void;- onSelect: (id: string) => void;+ /** Replaces the bin selection; cards and the marquee both call it. */+ onSelect: (ids: string[]) => void;onImport: (paths: string[]) => void;onRemove: (id: string) => void;+ /** Deletes everything in the current bin selection, as one undo step. */+ onRemoveSelected: () => void;onDismissError: () => void;/** Called once the pointer has moved far enough to count as a drag. */onBeginDrag: (item: MediaItem, clientX: number, clientY: number) => void;@@ -194,7 +198,7 @@ export function MediaBin({<MediaPageitems={items}filter={filter}- selectedId={selectedId}+ selectedIds={selectedIds}busy={busy}error={error}dropping={dropping}@@ -202,6 +206,7 @@ export function MediaBin({onSelect={onSelect}onImport={onImport}onRemove={onRemove}+ onRemoveSelected={onRemoveSelected}onDismissError={onDismissError}onBeginDrag={onBeginDrag}onAddToTimeline={onAddToTimeline}@@ -329,7 +334,7 @@ const CARD_GRID = "grid grid-cols-[repeat(auto-fill,minmax(88px,1fr))] gap-2 px-function MediaPage({items,filter,- selectedId,+ selectedIds,busy,error,dropping,@@ -337,6 +342,7 @@ function MediaPage({onSelect,onImport,onRemove,+ onRemoveSelected,onDismissError,onBeginDrag,onAddToTimeline,@@ -344,14 +350,16 @@ function MediaPage({}: {items: MediaItem[];filter: BinFilter;- selectedId: string | null;+ selectedIds: readonly string[];busy: boolean;error: string | null;dropping: boolean;assets: MediaAssets;- onSelect: (id: string) => void;+ onSelect: (ids: string[]) => void;onImport: (paths: string[]) => void;onRemove: (id: string) => void;+ /** Deletes everything in the current bin selection, as one undo step. */+ onRemoveSelected: () => void;onDismissError: () => void;onBeginDrag: (item: MediaItem, clientX: number, clientY: number) => void;onAddToTimeline: (mediaId: string) => void;@@ -380,6 +388,58 @@ function MediaPage({else if (typeof chosen === "string") onImport([chosen]);};+ /**+ * Marquee selection over the card grid.+ *+ * A press on the grid's background (never on a card - cards are drag+ * sources) starts a band in client coordinates; every move re-derives the+ * selection from the cards' live rects, so scrolled positions and wrapped+ * rows need no bookkeeping. Shift adds to the selection that existed when+ * the band started, like the timeline's marquee.+ */+ const grid = useRef<HTMLDivElement>(null);+ const [band, setBand] = useState<{ x0: number; y0: number; x1: number; y1: number } | null>(+ null,+ );+ const beginMarquee = (event: ReactPointerEvent<HTMLDivElement>) => {+ if (event.button !== 0) return;+ if ((event.target as Element).closest("[data-media-card]")) return;+ const basis = event.shiftKey ? [...selectedIds] : [];+ if (!event.shiftKey) onSelect([]);+ const origin = { x: event.clientX, y: event.clientY };+ setBand({ x0: origin.x, y0: origin.y, x1: origin.x, y1: origin.y });++ const caught = (x: number, y: number) => {+ const left = Math.min(origin.x, x);+ const right = Math.max(origin.x, x);+ const top = Math.min(origin.y, y);+ const bottom = Math.max(origin.y, y);+ const ids: string[] = [];+ grid.current+ ?.querySelectorAll<HTMLElement>("[data-media-card]")+ .forEach((card) => {+ const rect = card.getBoundingClientRect();+ const hit =+ rect.left < right && rect.right > left && rect.top < bottom && rect.bottom > top;+ const id = card.dataset.mediaCard;+ if (hit && id) ids.push(id);+ });+ return ids;+ };++ const onMove = (move: PointerEvent) => {+ setBand({ x0: origin.x, y0: origin.y, x1: move.clientX, y1: move.clientY });+ onSelect([...new Set([...basis, ...caught(move.clientX, move.clientY)])]);+ };+ const onUp = () => {+ window.removeEventListener("pointermove", onMove);+ window.removeEventListener("pointerup", onUp);+ setBand(null);+ };+ window.addEventListener("pointermove", onMove);+ window.addEventListener("pointerup", onUp);+ };+/*** Starts a drag using raw pointer events rather than HTML5 drag-and-drop.*@@ -413,7 +473,9 @@ function MediaPage({const visible = items.filter((item) => filter[item.kind]);return (- <>+ // The grid area is the marquee surface; pressing empty space drags a+ // selection band, pressing a card starts a media drag.+ <div ref={grid} onPointerDown={beginMarquee} className="flex min-h-full flex-col"><div className="px-2 pb-2 pt-2"><buttontype="button"@@ -429,6 +491,23 @@ function MediaPage({</button></div>+ {selectedIds.length > 1 && (+ <div className="mx-2 mb-2 flex items-center justify-between rounded-lg bg-sunken+ px-2.5 py-1.5">+ <span className="text-[11px] text-secondary">+ {selectedIds.length} selected - drag any of them to place all+ </span>+ <button+ type="button"+ onClick={onRemoveSelected}+ className="cursor-pointer rounded px-2 py-0.5 text-[11px] font-medium text-danger+ transition-colors hover:bg-danger-soft"+ >+ Delete+ </button>+ </div>+ )}+{error && <ErrorNotice message={error} onDismiss={onDismissError} className="mx-2 mb-2" />}{visible.length === 0 ? (@@ -451,8 +530,18 @@ function MediaPage({{visible.map((item) => (<likey={item.id}+ data-media-card={item.id}onPointerDown={(event) => beginDrag(event, item)}- onClick={() => onSelect(item.id)}+ onClick={(event) => {+ const additive = event.shiftKey || event.metaKey || event.ctrlKey;+ onSelect(+ additive+ ? selectedIds.includes(item.id)+ ? selectedIds.filter((id) => id !== item.id)+ : [...selectedIds, item.id]+ : [item.id],+ );+ }}onDoubleClick={() => onAddToTimeline(item.id)}// The details that used to sit on a second line live here now.// They are worth having, but not worth a permanent row each.@@ -463,7 +552,7 @@ Drag onto a track, or double-click to add at the playhead`}><divclassName={`relative overflow-hidden rounded-lg transition-shadow ${- item.id === selectedId+ selectedIds.includes(item.id)? "ring-2 ring-accent": "ring-1 ring-hairline group-hover:ring-hairline-strong"}`}@@ -547,7 +636,22 @@ Drag onto a track, or double-click to add at the playhead`}))}</ul>)}- </>++ {band && (+ <div+ aria-hidden+ className="pointer-events-none fixed z-40 border"+ style={{+ left: Math.min(band.x0, band.x1),+ top: Math.min(band.y0, band.y1),+ width: Math.abs(band.x1 - band.x0),+ height: Math.abs(band.y1 - band.y0),+ background: "var(--color-accent-soft)",+ borderColor: "var(--color-accent)",+ }}+ />+ )}+ </div>);}