;
- applyMarqueeSelection: (selections: DomEditSelection[], additive: boolean) => DomSelectionResult;
+ applyMarqueeSelection: (
+ selections: DomEditSelection[],
+ mode: MarqueeSelectionMode,
+ ) => DomSelectionResult;
}
diff --git a/packages/studio/src/hooks/useStudioUrlState.ts b/packages/studio/src/hooks/useStudioUrlState.ts
index 03b628c81a..50dfe1a4fb 100644
--- a/packages/studio/src/hooks/useStudioUrlState.ts
+++ b/packages/studio/src/hooks/useStudioUrlState.ts
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { usePlayerStore } from "../player";
import { findElementForSelection, type DomEditSelection } from "../components/editor/domEditing";
+import type { MarqueeSelectionMode } from "../utils/marqueeGeometry";
import { clampNumber, type RightPanelTab } from "../utils/studioHelpers";
import { parseProjectIdFromHash } from "../utils/projectRouting";
import {
@@ -24,7 +25,7 @@ interface UseStudioUrlStateParams {
activeCompPathHydrated: boolean;
domEditSelection: DomEditSelection | null;
domEditGroupSelections: DomEditSelection[];
- applyMarqueeSelection: (selections: DomEditSelection[], additive: boolean) => void;
+ applyMarqueeSelection: (selections: DomEditSelection[], mode: MarqueeSelectionMode) => void;
buildDomSelectionFromTarget: (
target: HTMLElement,
options?: { preferClipAncestor?: boolean; skipSourceProbe?: boolean },
@@ -252,7 +253,7 @@ export function useStudioUrlState({
if (!primary) return applyDomSelection(null, { revealPanel: false });
if (group.length === 0) return applyDomSelection(primary, { revealPanel: false });
// Missing group members are dropped without failing the rest.
- applyMarqueeSelection(members, false);
+ applyMarqueeSelection(members, "replace");
});
return true;
},
diff --git a/packages/studio/src/hooks/useTimelineSelectionPreviewSync.test.tsx b/packages/studio/src/hooks/useTimelineSelectionPreviewSync.test.tsx
index 831087268b..f943cf9a9a 100644
--- a/packages/studio/src/hooks/useTimelineSelectionPreviewSync.test.tsx
+++ b/packages/studio/src/hooks/useTimelineSelectionPreviewSync.test.tsx
@@ -5,6 +5,7 @@ import { createRoot } from "react-dom/client";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { TimelineElement } from "../player";
import type { DomEditSelection } from "../components/editor/domEditing";
+import type { MarqueeSelectionMode } from "../utils/marqueeGeometry";
import { installReactActEnvironment, makeSelection } from "./domSelectionTestHarness";
import { useTimelineSelectionPreviewSync } from "./useTimelineSelectionPreviewSync";
@@ -23,7 +24,7 @@ interface HarnessProps {
selection: DomEditSelection | null,
options?: { revealPanel?: boolean; additive?: boolean; preserveGroup?: boolean },
) => void;
- applyMarqueeSelection: (selections: DomEditSelection[], additive: boolean) => void;
+ applyMarqueeSelection: (selections: DomEditSelection[], mode: MarqueeSelectionMode) => void;
onSelectionNotFound: () => void;
}
@@ -100,7 +101,10 @@ describe("useTimelineSelectionPreviewSync", () => {
onSelectionNotFound: vi.fn(),
});
- expect(applyMarqueeSelection).toHaveBeenCalledWith([secondSelection, firstSelection], false);
+ expect(applyMarqueeSelection).toHaveBeenCalledWith(
+ [secondSelection, firstSelection],
+ "replace",
+ );
expect(applyDomSelection).not.toHaveBeenCalled();
harness.cleanup();
});
diff --git a/packages/studio/src/hooks/useTimelineSelectionPreviewSync.ts b/packages/studio/src/hooks/useTimelineSelectionPreviewSync.ts
index cabc162189..a927675a2d 100644
--- a/packages/studio/src/hooks/useTimelineSelectionPreviewSync.ts
+++ b/packages/studio/src/hooks/useTimelineSelectionPreviewSync.ts
@@ -1,6 +1,7 @@
import { useEffect, useMemo, useRef } from "react";
import type { TimelineElement } from "../player";
import type { DomEditSelection } from "../components/editor/domEditing";
+import type { MarqueeSelectionMode } from "../utils/marqueeGeometry";
import { resolveTimelineIdForSelection } from "../utils/studioHelpers";
import { logSelect } from "../utils/selectDebug";
import { recordRetryAttempt, type RetryBudgetState } from "../utils/retryBudget";
@@ -24,7 +25,7 @@ interface UseTimelineSelectionPreviewSyncParams {
announce?: boolean;
},
) => void;
- applyMarqueeSelection: (selections: DomEditSelection[], additive: boolean) => void;
+ applyMarqueeSelection: (selections: DomEditSelection[], mode: MarqueeSelectionMode) => void;
onSelectionNotFound: () => void;
}
@@ -96,7 +97,7 @@ function applyResolvedSelections(
} else if (selections.length === 1) {
applyDomSelection(selections[0]);
} else {
- applyMarqueeSelection(selections, false);
+ applyMarqueeSelection(selections, "replace");
}
}
diff --git a/packages/studio/src/index.ts b/packages/studio/src/index.ts
index e799d00a28..ec2f5f038d 100644
--- a/packages/studio/src/index.ts
+++ b/packages/studio/src/index.ts
@@ -282,7 +282,12 @@ export { useMarqueeGestures } from "./components/editor/marqueeCommit";
export type { MarqueeGestures, MarqueeGesturesDeps } from "./components/editor/marqueeCommit";
export { MarqueeOverlay } from "./components/editor/MarqueeOverlay";
export type { MarqueeOverlayProps } from "./components/editor/MarqueeOverlay";
-export type { Rect as MarqueeRect } from "./utils/marqueeGeometry";
+export type {
+ Rect as MarqueeRect,
+ MarqueeBand,
+ MarqueeSelectionMode,
+} from "./utils/marqueeGeometry";
+export { resolveMarqueeMode } from "./utils/marqueeGeometry";
export { buildStudioTools } from "./webmcp/useStudioAgentTools";
export type { StudioAgentToolsDeps } from "./webmcp/useStudioAgentTools";
diff --git a/packages/studio/src/player/components/TimelineCanvas.tsx b/packages/studio/src/player/components/TimelineCanvas.tsx
index 3929162034..da748ba0ed 100644
--- a/packages/studio/src/player/components/TimelineCanvas.tsx
+++ b/packages/studio/src/player/components/TimelineCanvas.tsx
@@ -226,18 +226,26 @@ export const TimelineCanvas = memo(function TimelineCanvas() {
/>
{/* Marquee (rubber-band) multi-select rectangle — mirrors the canvas
- MarqueeOverlay look: semi-transparent accent fill + dashed border. */}
+ MarqueeOverlay look: dashed accent border, danger-coloured while subtracting. */}
{props.marqueeRect && (
;
diff --git a/packages/studio/src/player/components/timelineMarquee.test.ts b/packages/studio/src/player/components/timelineMarquee.test.ts
index d82ecbf8c0..c13652e1d2 100644
--- a/packages/studio/src/player/components/timelineMarquee.test.ts
+++ b/packages/studio/src/player/components/timelineMarquee.test.ts
@@ -7,6 +7,7 @@ import {
getTimelineClipRect,
getMarqueeClipCandidates,
computeMarqueeSelection,
+ survivingPrimary,
} from "./timelineMarquee";
import { createTimelineClipIndex } from "../lib/timelineClipIndex";
import type { TimelineElement } from "../store/playerStore";
@@ -242,6 +243,61 @@ describe("computeMarqueeSelection", () => {
expect(primaryId).toBe("c");
});
+ it("subtracts the hits from the base selection and names no new primary", () => {
+ const marquee = { left: ORIGIN, top: row0Top, width: 50, height: 10 };
+ const { ids, primaryId } = computeMarqueeSelection({
+ clips,
+ rowGeometry,
+ pps,
+ contentOrigin: ORIGIN,
+ marquee,
+ baseSelection: ["a", "b", "c"],
+ mode: "subtract",
+ });
+ expect(ids).toEqual(new Set(["b", "c"]));
+ expect(primaryId).toBeNull();
+ });
+
+ it("subtracting from an empty or unrelated base selects nothing", () => {
+ const marquee = { left: ORIGIN, top: row0Top, width: 50, height: 10 };
+ expect(
+ computeMarqueeSelection({
+ clips,
+ rowGeometry,
+ pps,
+ contentOrigin: ORIGIN,
+ marquee,
+ mode: "subtract",
+ }).ids,
+ ).toEqual(new Set());
+ expect(
+ computeMarqueeSelection({
+ clips,
+ rowGeometry,
+ pps,
+ contentOrigin: ORIGIN,
+ marquee,
+ baseSelection: ["b"],
+ mode: "subtract",
+ }).ids,
+ ).toEqual(new Set(["b"]));
+ });
+
+ it("add mode is the default when a base is given", () => {
+ const marquee = { left: ORIGIN, top: row0Top, width: 50, height: 10 };
+ const explicit = computeMarqueeSelection({
+ clips,
+ rowGeometry,
+ pps,
+ contentOrigin: ORIGIN,
+ marquee,
+ baseSelection: ["b"],
+ mode: "add",
+ });
+ expect(explicit.ids).toEqual(new Set(["a", "b"]));
+ expect(explicit.primaryId).toBe("a");
+ });
+
it("shrinking the rect live drops clips it no longer covers", () => {
const wide = { left: ORIGIN, top: row0Top, width: 320, height: 10 };
const narrow = { left: ORIGIN, top: row0Top, width: 80, height: 10 };
@@ -268,6 +324,18 @@ describe("computeMarqueeSelection", () => {
});
});
+describe("survivingPrimary", () => {
+ it("keeps the pre-drag primary while it is still selected", () => {
+ expect(survivingPrimary(new Set(["a", "b"]), "b")).toBe("b");
+ });
+
+ it("falls back to any remaining id, or null when nothing is left", () => {
+ expect(survivingPrimary(new Set(["a", "b"]), "c")).toBe("a");
+ expect(survivingPrimary(new Set(), "c")).toBeNull();
+ expect(survivingPrimary(new Set(["a"]), null)).toBe("a");
+ });
+});
+
describe("getMarqueeClipCandidates", () => {
it("queries only the intersecting rows and time span", () => {
const rowGeometry = createTimelineRowGeometry([0, 1, 2], [TRACK_H, TRACK_H, TRACK_H]);
diff --git a/packages/studio/src/player/components/timelineMarquee.ts b/packages/studio/src/player/components/timelineMarquee.ts
index 1b792a4211..8a0e48cc03 100644
--- a/packages/studio/src/player/components/timelineMarquee.ts
+++ b/packages/studio/src/player/components/timelineMarquee.ts
@@ -1,5 +1,5 @@
import { RULER_H, CLIP_Y, TRACK_H, type TimelineRowGeometry } from "./timelineLayout";
-import { rectsOverlap, type Rect } from "../../utils/marqueeGeometry";
+import { rectsOverlap, type MarqueeSelectionMode, type Rect } from "../../utils/marqueeGeometry";
import { queryTimelineClipIndex, type TimelineClipIndex } from "../lib/timelineClipIndex";
import type { TimelineElement } from "../store/playerStore";
@@ -84,10 +84,10 @@ export function getTimelineClipRect(
}
export interface MarqueeSelectionResult {
- /** Every clip id the marquee currently covers (plus the additive base). */
+ /** The marquee's hits, unioned with or removed from the base selection. */
ids: Set;
/** The last marquee-hit clip in element order — the primary selection.
- * Null when the marquee covers nothing new (caller keeps its current primary). */
+ * Null when the marquee selects nothing new (caller keeps its current primary). */
primaryId: string | null;
}
@@ -125,9 +125,16 @@ export function getMarqueeClipCandidates(input: {
return candidates;
}
+/** The primary after a subtract: the pre-drag primary if it survived, else any survivor. */
+export function survivingPrimary(ids: Set, basePrimary: string | null): string | null {
+ if (basePrimary && ids.has(basePrimary)) return basePrimary;
+ for (const id of ids) return id;
+ return null;
+}
+
/**
* Live marquee selection: every clip whose rendered rect intersects the marquee.
- * `baseSelection` (shift/cmd-additive) is unioned in but never affects primaryId.
+ * `baseSelection` gains the hits in `add` mode and loses them in `subtract` mode.
*/
export function computeMarqueeSelection(input: {
clips: MarqueeClipInput[];
@@ -136,12 +143,17 @@ export function computeMarqueeSelection(input: {
contentOrigin: number;
marquee: Rect;
baseSelection?: Iterable;
+ mode?: MarqueeSelectionMode;
}): MarqueeSelectionResult {
+ const subtract = input.mode === "subtract";
const ids = new Set(input.baseSelection ?? []);
let primaryId: string | null = null;
for (const clip of input.clips) {
const rect = getTimelineClipRect(clip, input.rowGeometry, input.pps, input.contentOrigin);
- if (rect && rectsOverlap(rect, input.marquee)) {
+ if (!rect || !rectsOverlap(rect, input.marquee)) continue;
+ if (subtract) {
+ ids.delete(clip.id);
+ } else {
ids.add(clip.id);
primaryId = clip.id;
}
diff --git a/packages/studio/src/player/components/timelineMarqueeCommit.ts b/packages/studio/src/player/components/timelineMarqueeCommit.ts
new file mode 100644
index 0000000000..9a5db7b785
--- /dev/null
+++ b/packages/studio/src/player/components/timelineMarqueeCommit.ts
@@ -0,0 +1,74 @@
+import type { TimelineRowGeometry } from "./timelineLayout";
+import type { TimelineClipIndex } from "../lib/timelineClipIndex";
+import { usePlayerStore, type TimelineElement } from "../store/playerStore";
+import type { MarqueeSelectionMode, Rect } from "../../utils/marqueeGeometry";
+import {
+ computeMarqueeSelection,
+ getMarqueeClipCandidates,
+ survivingPrimary,
+ type MarqueeClipInput,
+} from "./timelineMarquee";
+
+export interface MarqueeDragState {
+ originX: number;
+ originY: number;
+ /** Pre-drag selection, restored on Escape-cancel. */
+ baseIds: Set;
+ basePrimary: string | null;
+ /** Base mode (cmd/ctrl at pointerdown adds); Shift or Alt held on the pointer override it. */
+ mode: MarqueeSelectionMode;
+ /** True once the pointer travelled past the click threshold. */
+ active: boolean;
+}
+
+export function snapshotSelection(): { ids: Set; primary: string | null } {
+ const s = usePlayerStore.getState();
+ const ids = new Set(s.selectedElementIds);
+ if (s.selectedElementId) ids.add(s.selectedElementId);
+ return { ids, primary: s.selectedElementId };
+}
+
+function toMarqueeClips(elements: TimelineElement[]): MarqueeClipInput[] {
+ return elements.map((el) => ({
+ id: el.key ?? el.id,
+ start: el.start,
+ duration: el.duration,
+ track: el.track,
+ }));
+}
+
+/** Computes the live selection for a marquee rect against the pre-drag base and commits it. */
+export function commitMarqueeSelection(
+ rect: Rect,
+ mode: MarqueeSelectionMode,
+ marquee: MarqueeDragState,
+ clipIndex: TimelineClipIndex,
+ rowGeometry: TimelineRowGeometry,
+ pps: number,
+ contentOrigin: number,
+): void {
+ const candidates = getMarqueeClipCandidates({
+ clipIndex,
+ rowGeometry,
+ marquee: rect,
+ pps,
+ contentOrigin,
+ });
+ const { ids, primaryId } = computeMarqueeSelection({
+ clips: toMarqueeClips([...candidates]),
+ rowGeometry,
+ pps,
+ contentOrigin,
+ marquee: rect,
+ baseSelection: mode === "replace" ? undefined : marquee.baseIds,
+ mode,
+ });
+ const store = usePlayerStore.getState();
+ let primary = primaryId;
+ if (mode === "add") primary ??= marquee.basePrimary;
+ if (mode === "subtract") primary = survivingPrimary(ids, marquee.basePrimary);
+ // Primary FIRST: setSelectedElementId collapses the multi-select set, so the set
+ // must be written after it or the marquee selection would be wiped every frame.
+ store.setSelectedElementId(primary);
+ store.setSelectedElementIds(ids);
+}
diff --git a/packages/studio/src/player/components/useTimelineRangeSelection.test.tsx b/packages/studio/src/player/components/useTimelineRangeSelection.test.tsx
index 83cbc0b4ee..b7fb920d6e 100644
--- a/packages/studio/src/player/components/useTimelineRangeSelection.test.tsx
+++ b/packages/studio/src/player/components/useTimelineRangeSelection.test.tsx
@@ -103,20 +103,31 @@ function renderHarness(sessionEpoch = 1) {
function dragMarquee(
view: ReturnType,
- options: { secondPointer?: boolean; release?: boolean } = {},
+ options: {
+ secondPointer?: boolean;
+ release?: boolean;
+ down?: Partial;
+ move?: Partial;
+ } = {},
): void {
act(() => {
- view.api.handlePointerDown(pointer(view.scroll, 7, 0, FIRST_ROW_Y));
+ view.api.handlePointerDown(pointer(view.scroll, 7, 0, FIRST_ROW_Y, options.down));
if (options.secondPointer) {
view.api.handlePointerDown(pointer(view.scroll, 8, 500, FIRST_ROW_Y));
}
- view.api.handlePointerMove(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y));
+ view.api.handlePointerMove(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y, options.move));
if (options.release) {
- view.api.handlePointerUp(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y));
+ view.api.handlePointerUp(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y, options.move));
}
});
}
+function selectIds(primary: string, ...others: string[]): void {
+ const store = usePlayerStore.getState();
+ store.setSelectedElementId(primary);
+ store.setSelectedElementIds(new Set([primary, ...others]));
+}
+
function expectSelectedIds(...ids: string[]): void {
expect(usePlayerStore.getState().selectedElementIds).toEqual(new Set(ids));
}
@@ -190,6 +201,89 @@ describe("useTimelineRangeSelection", () => {
unmountHarness(view);
});
+ it("replaces the selection with the covered clips when no modifier is held", () => {
+ selectIds("base");
+ const view = renderHarness();
+ dragMarquee(view, { release: true });
+
+ expectSelectedIds("first", "offscreen");
+ expect(view.api.marqueeRect).toBeNull();
+ unmountHarness(view);
+ });
+
+ it("adds the covered clips to the selection while Shift is held", () => {
+ selectIds("base");
+ const view = renderHarness();
+ dragMarquee(view, { move: { shiftKey: true } });
+
+ expect(view.api.marqueeRect?.mode).toBe("add");
+ expectSelectedIds("base", "first", "offscreen");
+ unmountHarness(view);
+ });
+
+ it("removes the covered clips from the selection while Alt is held", () => {
+ selectIds("first", "offscreen", "base");
+ const view = renderHarness();
+ dragMarquee(view, { down: { altKey: true }, move: { altKey: true }, release: true });
+
+ expectSelectedIds("base");
+ expect(usePlayerStore.getState().selectedElementId).toBe("base");
+ unmountHarness(view);
+ });
+
+ it("re-anchors on a survivor when Alt removes the primary", () => {
+ selectIds("first", "base");
+ const view = renderHarness();
+ dragMarquee(view, { move: { altKey: true } });
+
+ expect(view.api.marqueeRect?.mode).toBe("subtract");
+ expectSelectedIds("base");
+ expect(usePlayerStore.getState().selectedElementId).toBe("base");
+ unmountHarness(view);
+ });
+
+ it("Alt pressed mid-drag flips a Shift add into a subtract", () => {
+ selectIds("first", "base");
+ const view = renderHarness();
+ dragMarquee(view, { move: { shiftKey: true } });
+ expectSelectedIds("first", "base", "offscreen");
+
+ act(() => {
+ view.api.handlePointerMove(
+ pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y, { shiftKey: true, altKey: true }),
+ );
+ });
+
+ expect(view.api.marqueeRect?.mode).toBe("subtract");
+ expectSelectedIds("base");
+ unmountHarness(view);
+ });
+
+ it("the modifiers held at release decide: letting go of Alt turns the subtract into a replace", () => {
+ selectIds("first", "base");
+ const view = renderHarness();
+ dragMarquee(view, { down: { altKey: true }, move: { altKey: true } });
+ expectSelectedIds("base");
+
+ act(() => view.api.handlePointerUp(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y)));
+
+ expectSelectedIds("first", "offscreen");
+ expect(usePlayerStore.getState().selectedElementId).toBe("offscreen");
+ unmountHarness(view);
+ });
+
+ it("restores the pre-drag selection when an Alt marquee is cancelled", () => {
+ selectIds("first", "base");
+ const view = renderHarness();
+ dragMarquee(view, { move: { altKey: true } });
+ expectSelectedIds("base");
+
+ act(() => view.api.handlePointerCancel(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y)));
+ expectSelectedIds("first", "base");
+ expect(usePlayerStore.getState().selectedElementId).toBe("first");
+ unmountHarness(view);
+ });
+
it("cancels a live marquee when the project session changes", () => {
usePlayerStore.getState().setSelectedElementId("base");
const view = renderHarness(1);
diff --git a/packages/studio/src/player/components/useTimelineRangeSelection.ts b/packages/studio/src/player/components/useTimelineRangeSelection.ts
index 6ac7ef96fc..f69a7945b9 100644
--- a/packages/studio/src/player/components/useTimelineRangeSelection.ts
+++ b/packages/studio/src/player/components/useTimelineRangeSelection.ts
@@ -8,15 +8,18 @@ import {
import type { TimelineElement } from "../store/playerStore";
import { liveTime, usePlayerStore } from "../store/playerStore";
import { getTimelineScrubTime } from "./timelineLayout";
+import { getMarqueeRect, isMarqueeDrag, isTimelineRulerPress } from "./timelineMarquee";
import {
- computeMarqueeSelection,
- getMarqueeClipCandidates,
- getMarqueeRect,
- isMarqueeDrag,
- isTimelineRulerPress,
- type MarqueeClipInput,
-} from "./timelineMarquee";
-import type { Rect } from "../../utils/marqueeGeometry";
+ commitMarqueeSelection,
+ snapshotSelection,
+ type MarqueeDragState,
+} from "./timelineMarqueeCommit";
+import {
+ resolveMarqueeMode,
+ type MarqueeBand,
+ type MarqueeModifiers,
+ type MarqueeSelectionMode,
+} from "../../utils/marqueeGeometry";
import type { TimelineRowGeometry } from "./timelineLayout";
import type { TimelineClipIndex } from "../lib/timelineClipIndex";
@@ -39,69 +42,7 @@ interface UseTimelineRangeSelectionInput {
sessionEpoch: number;
}
-interface MarqueeDragState {
- originX: number;
- originY: number;
- /** Pre-drag selection, restored on Escape-cancel. */
- baseIds: Set;
- basePrimary: string | null;
- /** Union new hits with baseIds (shift/cmd/ctrl at pointerdown). */
- additive: boolean;
- /** True once the pointer travelled past the click threshold. */
- active: boolean;
-}
-
-function snapshotSelection(): { ids: Set; primary: string | null } {
- const s = usePlayerStore.getState();
- const ids = new Set(s.selectedElementIds);
- if (s.selectedElementId) ids.add(s.selectedElementId);
- return { ids, primary: s.selectedElementId };
-}
-
-function toMarqueeClips(elements: TimelineElement[]): MarqueeClipInput[] {
- return elements.map((el) => ({
- id: el.key ?? el.id,
- start: el.start,
- duration: el.duration,
- track: el.track,
- }));
-}
-
-/**
- * Compute the live selection for a marquee rect and commit it to the store.
- * Shift held mid-drag (or cmd/ctrl at pointerdown) unions the new hits with the
- * pre-drag selection (marquee.baseIds / basePrimary).
- */
-function commitMarqueeSelection(
- rect: Rect,
- additive: boolean,
- marquee: MarqueeDragState,
- clipIndex: TimelineClipIndex,
- rowGeometry: TimelineRowGeometry,
- pps: number,
- contentOrigin: number,
-): void {
- const candidates = getMarqueeClipCandidates({
- clipIndex,
- rowGeometry,
- marquee: rect,
- pps,
- contentOrigin,
- });
- const { ids, primaryId } = computeMarqueeSelection({
- clips: toMarqueeClips([...candidates]),
- rowGeometry,
- pps,
- contentOrigin,
- marquee: rect,
- baseSelection: additive ? marquee.baseIds : undefined,
- });
- const store = usePlayerStore.getState();
- // Primary FIRST: setSelectedElementId collapses the multi-select set, so the set
- // must be written after it or the marquee selection would be wiped every frame.
- store.setSelectedElementId(primaryId ?? (additive ? marquee.basePrimary : null));
- store.setSelectedElementIds(ids);
-}
+type MarqueePointer = { clientX: number; clientY: number } & MarqueeModifiers;
function canStartPointerGesture(
event: React.PointerEvent,
@@ -166,13 +107,10 @@ export function useTimelineRangeSelection({
// Marquee (rubber-band) multi-select on the empty timeline body.
const marqueeRef = useRef(null);
- const [marqueeRect, setMarqueeRect] = useState(null);
- // Edge auto-scroll during a marquee drag: last pointer position (client-space)
- // + shift flag, re-applied each RAF frame while the view scrolls under a
- // stationary pointer, so the marquee can extend past the visible area.
- const marqueePointerRef = useRef<{ clientX: number; clientY: number; shiftKey: boolean } | null>(
- null,
- );
+ const [marqueeRect, setMarqueeRect] = useState(null);
+ // Edge auto-scroll: the last client-space pointer and modifiers, re-applied each
+ // RAF frame while the view scrolls, so the marquee can extend past the visible area.
+ const marqueePointerRef = useRef(null);
const marqueeScrollRaf = useRef(0);
/** Pointer position → canvas/content coordinates (same space as clip rects). */
@@ -194,7 +132,7 @@ export function useTimelineRangeSelection({
// view scrolls naturally extends the rect toward the newly revealed area.
// Shared by the pointermove handler and the edge auto-scroll stepper.
const applyMarqueeAtClient = useCallback(
- (clientX: number, clientY: number, shiftKey: boolean) => {
+ (clientX: number, clientY: number, modifiers: MarqueeModifiers) => {
const marquee = marqueeRef.current;
if (!marquee || !isGestureSessionCurrent()) return;
const point = toContentPoint(clientX, clientY);
@@ -204,13 +142,13 @@ export function useTimelineRangeSelection({
}
marquee.active = true;
const rect = getMarqueeRect(marquee.originX, marquee.originY, point.x, point.y);
- setMarqueeRect(rect);
- // Live selection: every clip the box currently covers. Shift held
- // mid-drag (or cmd/ctrl at pointerdown) adds to the prior selection.
- const additive = marquee.additive || shiftKey;
+ // Live selection: every clip the box currently covers. Shift held mid-drag
+ // (or cmd/ctrl at pointerdown) adds to the prior selection; Alt removes.
+ const mode = resolveMarqueeMode(modifiers, marquee.mode);
+ setMarqueeRect({ ...rect, mode });
commitMarqueeSelection(
rect,
- additive,
+ mode,
marquee,
clipIndex,
rowGeometryRef.current,
@@ -246,13 +184,13 @@ export function useTimelineRangeSelection({
// Re-run at the SAME client point: toContentPoint folds in the new scroll, so
// the marquee's moving corner tracks the revealed content.
- applyMarqueeAtClient(pointer.clientX, pointer.clientY, pointer.shiftKey);
+ applyMarqueeAtClient(pointer.clientX, pointer.clientY, pointer);
marqueeScrollRaf.current = requestAnimationFrame(stepMarqueeAutoScroll);
}, [scrollRef, applyMarqueeAtClient, isGestureSessionCurrent]);
const syncMarqueeAutoScroll = useCallback(
- (clientX: number, clientY: number, shiftKey: boolean) => {
- marqueePointerRef.current = { clientX, clientY, shiftKey };
+ (clientX: number, clientY: number, modifiers: MarqueeModifiers) => {
+ marqueePointerRef.current = { clientX, clientY, ...modifiers };
const action = resolveTimelineAutoScrollLoopAction(
scrollRef.current,
clientX,
@@ -298,17 +236,20 @@ export function useTimelineRangeSelection({
[isDragging, seekFromX],
);
- const beginMarquee = useCallback((point: { x: number; y: number }, additive: boolean) => {
- const base = snapshotSelection();
- marqueeRef.current = {
- originX: point.x,
- originY: point.y,
- baseIds: base.ids,
- basePrimary: base.primary,
- additive,
- active: false,
- };
- }, []);
+ const beginMarquee = useCallback(
+ (point: { x: number; y: number }, mode: MarqueeSelectionMode) => {
+ const base = snapshotSelection();
+ marqueeRef.current = {
+ originX: point.x,
+ originY: point.y,
+ baseIds: base.ids,
+ basePrimary: base.primary,
+ mode,
+ active: false,
+ };
+ },
+ [],
+ );
const handlePointerDown = useCallback(
(e: React.PointerEvent) => {
@@ -335,7 +276,7 @@ export function useTimelineRangeSelection({
}
// Empty body press → pending marquee. A plain click (no drag past the
// threshold) deselects on pointerup; a drag draws the marquee. Never scrubs.
- beginMarquee(point, e.metaKey || e.ctrlKey);
+ beginMarquee(point, e.metaKey || e.ctrlKey ? "add" : "replace");
},
[beginRangeSelection, beginScrub, beginMarquee, scrollRef, setShowPopover, toContentPoint],
);
@@ -398,10 +339,10 @@ export function useTimelineRangeSelection({
}
const marquee = marqueeRef.current;
if (marquee) {
- applyMarqueeAtClient(e.clientX, e.clientY, e.shiftKey);
+ applyMarqueeAtClient(e.clientX, e.clientY, e);
// Edge auto-scroll: once the drag is live, scroll when the pointer nears
// a viewport edge so the marquee can extend past the visible area.
- if (marquee.active) syncMarqueeAutoScroll(e.clientX, e.clientY, e.shiftKey);
+ if (marquee.active) syncMarqueeAutoScroll(e.clientX, e.clientY, e);
return;
}
if (!isDragging.current) return;
@@ -475,20 +416,29 @@ export function useTimelineRangeSelection({
const handlePointerUp = useCallback(
(e?: React.PointerEvent) => {
if (!canFinishPointerGesture(e)) return;
+ const marquee = marqueeRef.current;
+ // The modifiers held at release decide, as on the canvas.
+ if (e && marquee?.active) applyMarqueeAtClient(e.clientX, e.clientY, e);
activePointerIdRef.current = null;
gestureEpochRef.current = null;
if (isRangeSelecting.current) {
finishRangeSelection();
return;
}
- const marquee = marqueeRef.current;
if (marquee) {
finishMarquee(marquee);
return;
}
if (isDragging.current) finishScrub();
},
- [canFinishPointerGesture, finishRangeSelection, finishMarquee, finishScrub, isDragging],
+ [
+ canFinishPointerGesture,
+ finishRangeSelection,
+ finishMarquee,
+ finishScrub,
+ isDragging,
+ applyMarqueeAtClient,
+ ],
);
const cancelActiveGesture = useCallback(
diff --git a/packages/studio/src/styles/theme.css b/packages/studio/src/styles/theme.css
index e77e98b82e..5d7b0938a4 100644
--- a/packages/studio/src/styles/theme.css
+++ b/packages/studio/src/styles/theme.css
@@ -196,6 +196,7 @@
--timeline-accent-hover: var(--color-on-hover);
--timeline-accent-button-bg: var(--color-on);
--timeline-danger: color-mix(in oklab, var(--color-danger) 70%, transparent);
+ --timeline-danger-fill: color-mix(in oklab, var(--color-danger) 10%, transparent);
--timeline-info-bg: rgba(59, 130, 246, 0.12);
--timeline-info-border: rgba(59, 130, 246, 0.4);
--timeline-dialog-bg: var(--color-raised);
diff --git a/packages/studio/src/utils/marqueeGeometry.test.ts b/packages/studio/src/utils/marqueeGeometry.test.ts
index 75065b2e2e..a11ab05520 100644
--- a/packages/studio/src/utils/marqueeGeometry.test.ts
+++ b/packages/studio/src/utils/marqueeGeometry.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { rectsOverlap } from "./marqueeGeometry";
+import { rectsOverlap, resolveMarqueeMode } from "./marqueeGeometry";
describe("rectsOverlap", () => {
it("overlapping rects", () => {
@@ -38,3 +38,20 @@ describe("rectsOverlap", () => {
).toBe(true);
});
});
+
+describe("resolveMarqueeMode", () => {
+ it("replaces with no modifier, adds with Shift, subtracts with Alt", () => {
+ expect(resolveMarqueeMode({ shiftKey: false, altKey: false })).toBe("replace");
+ expect(resolveMarqueeMode({ shiftKey: true, altKey: false })).toBe("add");
+ expect(resolveMarqueeMode({ shiftKey: false, altKey: true })).toBe("subtract");
+ });
+
+ it("lets Alt win over Shift", () => {
+ expect(resolveMarqueeMode({ shiftKey: true, altKey: true })).toBe("subtract");
+ });
+
+ it("keeps the base mode when no modifier is held", () => {
+ expect(resolveMarqueeMode({ shiftKey: false, altKey: false }, "add")).toBe("add");
+ expect(resolveMarqueeMode({ shiftKey: false, altKey: true }, "add")).toBe("subtract");
+ });
+});
diff --git a/packages/studio/src/utils/marqueeGeometry.ts b/packages/studio/src/utils/marqueeGeometry.ts
index 1a013f6c86..0131610c98 100644
--- a/packages/studio/src/utils/marqueeGeometry.ts
+++ b/packages/studio/src/utils/marqueeGeometry.ts
@@ -13,3 +13,23 @@ export function rectsOverlap(a: Rect, b: Rect): boolean {
a.top + a.height > b.top
);
}
+
+export type MarqueeSelectionMode = "replace" | "add" | "subtract";
+
+export interface MarqueeBand extends Rect {
+ mode: MarqueeSelectionMode;
+}
+
+export interface MarqueeModifiers {
+ shiftKey: boolean;
+ altKey: boolean;
+}
+
+export function resolveMarqueeMode(
+ modifiers: MarqueeModifiers,
+ base: MarqueeSelectionMode = "replace",
+): MarqueeSelectionMode {
+ if (modifiers.altKey) return "subtract";
+ if (modifiers.shiftKey) return "add";
+ return base;
+}
diff --git a/packages/studio/src/utils/studioUrlState.test.ts b/packages/studio/src/utils/studioUrlState.test.ts
index 19530c2ffc..6d70dad33a 100644
--- a/packages/studio/src/utils/studioUrlState.test.ts
+++ b/packages/studio/src/utils/studioUrlState.test.ts
@@ -218,7 +218,7 @@ describe("studio url state", () => {
await act(async () => {
await Promise.resolve();
});
- expect(applyMarqueeSelection).toHaveBeenCalledWith([primary, member], false);
+ expect(applyMarqueeSelection).toHaveBeenCalledWith([primary, member], "replace");
harness.unmount();
});