mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
feat(studio): alt marquee removes the covered items from the selection (#5680)
* feat(studio): alt marquee removes the covered items from the selection Shift already adds marquee hits to the selection on the canvas and the timeline; there was no way to take a few items back out of a large selection. Both marquee paths now carry a MarqueeSelectionMode (replace | add | subtract) resolved from the pointer modifiers in one helper, with Alt winning over Shift. Subtracting the primary re-anchors on a surviving member; subtracting everything clears the selection. The band and candidate outlines turn the danger colour while subtracting. Closes #5586 * fix(studio): same alt marquee rules on the canvas and the timeline Both surfaces now let the modifiers held at release decide: the timeline re-applies the marquee from the pointerup event before it finishes, so letting go of Alt mid-drag turns a subtract back into a replace, as the canvas already did. Alt at pointerdown no longer bakes a timeline base mode; Cmd/Ctrl still sets add. While subtracting, the canvas outlines only candidates that are in the current selection, so the band never suggests removing something that is not selected. The timeline commit helpers move to timelineMarqueeCommit.ts to keep the hook under the file-size cap.
This commit is contained in:
@@ -5,6 +5,7 @@ import { type DomEditSelection } from "./domEditing";
|
||||
import type { PreviewMouseDownOptions } from "../../hooks/usePreviewInteraction";
|
||||
import { useMarqueeGestures } from "./marqueeCommit";
|
||||
import { MarqueeOverlay } from "./MarqueeOverlay";
|
||||
import type { MarqueeSelectionMode } from "../../utils/marqueeGeometry";
|
||||
import { resolveDomEditGroupOverlayRect } from "./domEditOverlayGeometry";
|
||||
import { useZOrderCrossedFlash, ZOrderCrossedFlash } from "./useZOrderCrossedFlash";
|
||||
import { useCanvasContextMenuState } from "./useCanvasContextMenuState";
|
||||
@@ -103,7 +104,7 @@ export interface DomEditOverlayProps {
|
||||
onToggleRecording?: () => void;
|
||||
onMarqueeSelect?: (
|
||||
selections: DomEditSelection[],
|
||||
additive: boolean,
|
||||
mode: MarqueeSelectionMode,
|
||||
) => DomSelectionResult | void;
|
||||
/**
|
||||
* Delete the selected canvas element.
|
||||
@@ -341,6 +342,7 @@ export const DomEditOverlay = memo(function DomEditOverlay({
|
||||
activeCompositionPathRef,
|
||||
onMarqueeSelectRef,
|
||||
selectionRef,
|
||||
groupSelectionsRef,
|
||||
gestures,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Rect } from "../../utils/marqueeGeometry";
|
||||
import type { MarqueeBand, Rect } from "../../utils/marqueeGeometry";
|
||||
|
||||
export interface MarqueeOverlayProps {
|
||||
/** Elements the marquee currently intersects — outlined live before mouse-up. */
|
||||
candidateRects: Rect[];
|
||||
/** The marquee drag rectangle itself, or null when not marquee-selecting. */
|
||||
marqueeRect: Rect | null;
|
||||
marqueeRect: MarqueeBand | null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -13,20 +13,28 @@ export interface MarqueeOverlayProps {
|
||||
* DomEditOverlay to keep that file under the 600-line cap.
|
||||
*/
|
||||
export function MarqueeOverlay({ candidateRects, marqueeRect }: MarqueeOverlayProps) {
|
||||
const subtracting = marqueeRect?.mode === "subtract";
|
||||
const candidateClass = subtracting
|
||||
? "border-danger bg-danger/5"
|
||||
: "border-studio-accent bg-studio-accent/5";
|
||||
const bandClass = subtracting
|
||||
? "border-danger bg-danger/10"
|
||||
: "border-studio-accent bg-studio-accent/10";
|
||||
return (
|
||||
<>
|
||||
{candidateRects.map((r, i) => (
|
||||
<div
|
||||
key={i}
|
||||
aria-hidden="true"
|
||||
className="pointer-events-none absolute rounded-xs border border-studio-accent bg-studio-accent/5"
|
||||
className={`pointer-events-none absolute rounded-xs border ${candidateClass}`}
|
||||
style={{ left: r.left, top: r.top, width: r.width, height: r.height }}
|
||||
/>
|
||||
))}
|
||||
{marqueeRect && (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="pointer-events-none absolute border border-dashed border-studio-accent bg-studio-accent/10"
|
||||
data-marquee-mode={marqueeRect.mode}
|
||||
className={`pointer-events-none absolute border border-dashed ${bandClass}`}
|
||||
style={{
|
||||
left: marqueeRect.left,
|
||||
top: marqueeRect.top,
|
||||
|
||||
@@ -2,9 +2,15 @@
|
||||
import { act, useRef, type RefObject } from "react";
|
||||
import type { Root } from "react-dom/client";
|
||||
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
||||
import { installReactActEnvironment, mountReactHarness } from "../../hooks/domSelectionTestHarness";
|
||||
import {
|
||||
installReactActEnvironment,
|
||||
makeSelection,
|
||||
mountReactHarness,
|
||||
} from "../../hooks/domSelectionTestHarness";
|
||||
import type { DomEditSelection } from "./domEditing";
|
||||
import { trackStudioEvent } from "../../utils/studioTelemetry";
|
||||
import type { DomSelectionResult } from "../../hooks/useDomSelectionTypes";
|
||||
import type { MarqueeSelectionMode } from "../../utils/marqueeGeometry";
|
||||
import { useMarqueeGestures } from "./marqueeCommit";
|
||||
|
||||
vi.mock("../../utils/studioTelemetry", () => ({ trackStudioEvent: vi.fn() }));
|
||||
@@ -39,7 +45,13 @@ function Overlay() {
|
||||
onPointerMove={marquee.onPointerMove}
|
||||
onPointerUp={marquee.onPointerUp}
|
||||
>
|
||||
{marquee.marqueeRect && <div data-band data-width={marquee.marqueeRect.width} />}
|
||||
{marquee.marqueeRect && (
|
||||
<div
|
||||
data-band
|
||||
data-width={marquee.marqueeRect.width}
|
||||
data-mode={marquee.marqueeRect.mode}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -55,6 +67,7 @@ function MarqueeSurface({
|
||||
<div
|
||||
ref={overlayRef}
|
||||
data-band-overlay
|
||||
data-candidates={marquee.candidateRects.length}
|
||||
onPointerDown={marquee.begin}
|
||||
onPointerMove={marquee.onPointerMove}
|
||||
onPointerUp={marquee.onPointerUp}
|
||||
@@ -66,10 +79,12 @@ function TestMarquee({
|
||||
iframeRef,
|
||||
onSelect,
|
||||
resolveHits,
|
||||
groupSelectionsRef,
|
||||
}: {
|
||||
iframeRef: RefObject<HTMLIFrameElement | null>;
|
||||
onSelect: (selections: HTMLElement[], additive: boolean) => DomSelectionResult | void;
|
||||
onSelect: (selections: HTMLElement[], mode: MarqueeSelectionMode) => DomSelectionResult | void;
|
||||
resolveHits: (elements: HTMLElement[]) => HTMLElement[] | Promise<HTMLElement[]>;
|
||||
groupSelectionsRef?: RefObject<DomEditSelection[]>;
|
||||
}) {
|
||||
const overlayRef = useRef<HTMLDivElement>(null);
|
||||
const marquee = useMarqueeGestures({
|
||||
@@ -78,16 +93,27 @@ function TestMarquee({
|
||||
activeCompositionPathRef: useRef<string | null>("index.html"),
|
||||
onMarqueeSelectRef: { current: onSelect },
|
||||
resolveHits,
|
||||
groupSelectionsRef,
|
||||
});
|
||||
return <MarqueeSurface overlayRef={overlayRef} marquee={marquee} />;
|
||||
}
|
||||
|
||||
function previewWithTwoElements() {
|
||||
const iframe = document.createElement("iframe");
|
||||
const doc = document.implementation.createHTMLDocument("preview");
|
||||
doc.body.innerHTML =
|
||||
'<div data-composition-id="main"><h1 id="title">Title</h1><p id="subtitle">Subtitle</p></div>';
|
||||
Object.defineProperty(iframe, "contentDocument", { value: doc });
|
||||
return { iframe, doc };
|
||||
}
|
||||
|
||||
const pointer = (
|
||||
type: string,
|
||||
clientX: number,
|
||||
clientY: number,
|
||||
selector = "[data-overlay]",
|
||||
shiftKey = false,
|
||||
altKey = false,
|
||||
) =>
|
||||
act(() => {
|
||||
document.querySelector(selector)!.dispatchEvent(
|
||||
@@ -99,6 +125,7 @@ const pointer = (
|
||||
clientX,
|
||||
clientY,
|
||||
shiftKey,
|
||||
altKey,
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -214,7 +241,10 @@ it.each([
|
||||
doc.body.innerHTML =
|
||||
'<div data-composition-id="main"><h1 id="title">Title</h1><p id="subtitle">Subtitle</p></div>';
|
||||
Object.defineProperty(iframe, "contentDocument", { value: doc });
|
||||
const apply = vi.fn((_selections: HTMLElement[], _additive: boolean) => ({ changed, count }));
|
||||
const apply = vi.fn((_selections: HTMLElement[], _mode: MarqueeSelectionMode) => ({
|
||||
changed,
|
||||
count,
|
||||
}));
|
||||
const band = mountReactHarness(
|
||||
<TestMarquee
|
||||
iframeRef={{ current: iframe }}
|
||||
@@ -244,3 +274,106 @@ it.each([
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
["no modifier", false, false, "replace"],
|
||||
["Shift", true, false, "add"],
|
||||
["Alt", false, true, "subtract"],
|
||||
["Shift and Alt", true, true, "subtract"],
|
||||
] as const)("a band released with %s commits in %s mode", async (_, shiftKey, altKey, mode) => {
|
||||
const iframe = document.createElement("iframe");
|
||||
const doc = document.implementation.createHTMLDocument("preview");
|
||||
doc.body.innerHTML = '<div data-composition-id="main"><h1 id="title">Title</h1></div>';
|
||||
Object.defineProperty(iframe, "contentDocument", { value: doc });
|
||||
const apply = vi.fn((_selections: HTMLElement[], _mode: MarqueeSelectionMode) => undefined);
|
||||
const band = mountReactHarness(
|
||||
<TestMarquee
|
||||
iframeRef={{ current: iframe }}
|
||||
onSelect={apply}
|
||||
resolveHits={(elements) => elements}
|
||||
/>,
|
||||
);
|
||||
const fire = (type: string, x: number, y: number) =>
|
||||
pointer(type, x, y, "[data-band-overlay]", shiftKey, altKey);
|
||||
try {
|
||||
fire("pointerdown", 0, 0);
|
||||
fire("pointermove", 120, 90);
|
||||
await act(async () => {
|
||||
fire("pointerup", 120, 90);
|
||||
});
|
||||
expect(apply).toHaveBeenCalledTimes(1);
|
||||
expect(apply.mock.calls[0]![1]).toBe(mode);
|
||||
} finally {
|
||||
act(() => band.unmount());
|
||||
}
|
||||
});
|
||||
|
||||
it("the modifiers held at release decide: a band dragged with Alt but released without commits a replace", async () => {
|
||||
const { iframe } = previewWithTwoElements();
|
||||
const apply = vi.fn((_selections: HTMLElement[], _mode: MarqueeSelectionMode) => undefined);
|
||||
const band = mountReactHarness(
|
||||
<TestMarquee iframeRef={{ current: iframe }} onSelect={apply} resolveHits={(e) => e} />,
|
||||
);
|
||||
try {
|
||||
pointer("pointerdown", 0, 0, "[data-band-overlay]", false, true);
|
||||
pointer("pointermove", 120, 90, "[data-band-overlay]", false, true);
|
||||
await act(async () => {
|
||||
pointer("pointerup", 120, 90, "[data-band-overlay]", false, false);
|
||||
});
|
||||
expect(apply.mock.calls[0]![1]).toBe("replace");
|
||||
} finally {
|
||||
act(() => band.unmount());
|
||||
}
|
||||
});
|
||||
|
||||
it("while subtracting, only elements already in the selection are outlined as candidates", () => {
|
||||
const { iframe, doc } = previewWithTwoElements();
|
||||
const title = doc.getElementById("title")!;
|
||||
const groupSelectionsRef = { current: [makeSelection("Title", title)] };
|
||||
const band = mountReactHarness(
|
||||
<TestMarquee
|
||||
iframeRef={{ current: iframe }}
|
||||
onSelect={() => undefined}
|
||||
resolveHits={(e) => e}
|
||||
groupSelectionsRef={groupSelectionsRef}
|
||||
/>,
|
||||
);
|
||||
const candidates = () =>
|
||||
document.querySelector<HTMLElement>("[data-band-overlay]")?.dataset.candidates;
|
||||
try {
|
||||
pointer("pointerdown", 0, 0, "[data-band-overlay]");
|
||||
pointer("pointermove", 120, 90, "[data-band-overlay]");
|
||||
expect(candidates()).toBe("2");
|
||||
pointer("pointermove", 130, 90, "[data-band-overlay]", false, true);
|
||||
expect(candidates()).toBe("1");
|
||||
pointer("pointermove", 140, 90, "[data-band-overlay]", true, false);
|
||||
expect(candidates()).toBe("2");
|
||||
} finally {
|
||||
act(() => band.unmount());
|
||||
}
|
||||
});
|
||||
|
||||
it("the band reports the mode its modifiers select while it is drawn", () => {
|
||||
const mode = () => document.querySelector<HTMLElement>("[data-band]")?.dataset.mode;
|
||||
pointer("pointerdown", 10, 10);
|
||||
pointer("pointermove", 120, 90);
|
||||
expect(mode()).toBe("replace");
|
||||
pointer("pointermove", 130, 90, "[data-overlay]", true);
|
||||
expect(mode()).toBe("add");
|
||||
pointer("pointermove", 140, 90, "[data-overlay]", false, true);
|
||||
expect(mode()).toBe("subtract");
|
||||
});
|
||||
|
||||
it("a plain click with no band in flight replaces the selection with nothing", () => {
|
||||
const apply = vi.fn((_selections: HTMLElement[], _mode: MarqueeSelectionMode) => undefined);
|
||||
const band = mountReactHarness(
|
||||
<TestMarquee iframeRef={{ current: null }} onSelect={apply} resolveHits={(e) => e} />,
|
||||
);
|
||||
try {
|
||||
pointer("pointerdown", 0, 0, "[data-band-overlay]", false, true);
|
||||
pointer("pointerup", 0, 0, "[data-band-overlay]", false, true);
|
||||
expect(apply).toHaveBeenCalledWith([], "replace");
|
||||
} finally {
|
||||
act(() => band.unmount());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -7,7 +7,13 @@ import type { DomEditSelection } from "./domEditing";
|
||||
import { collectDomEditLayerItems, resolveDomEditSelection } from "./domEditingLayers";
|
||||
import { isElementComputedVisible } from "./domEditingElement";
|
||||
import { coversComposition } from "../../utils/studioPreviewHelpers";
|
||||
import { rectsOverlap, type Rect } from "../../utils/marqueeGeometry";
|
||||
import {
|
||||
rectsOverlap,
|
||||
resolveMarqueeMode,
|
||||
type MarqueeBand,
|
||||
type MarqueeSelectionMode,
|
||||
type Rect,
|
||||
} from "../../utils/marqueeGeometry";
|
||||
import { toVisibleOverlayRect } from "./domEditOverlayGeometry";
|
||||
import { movesGesture } from "./domEditOverlayGestures";
|
||||
|
||||
@@ -117,11 +123,12 @@ export interface MarqueeGesturesDeps<T = DomEditSelection> {
|
||||
overlayRef: React.RefObject<HTMLDivElement | null>;
|
||||
activeCompositionPathRef: React.RefObject<string | null>;
|
||||
onMarqueeSelectRef: React.RefObject<
|
||||
((selections: T[], additive: boolean) => DomSelectionResult | void) | undefined
|
||||
((selections: T[], mode: MarqueeSelectionMode) => DomSelectionResult | void) | undefined
|
||||
>;
|
||||
/** Turns the elements a drag touched into picks; without it, Studio's edit selections. */
|
||||
resolveHits?: (elements: HTMLElement[]) => T[] | Promise<T[]>;
|
||||
selectionRef?: React.RefObject<DomEditSelection | null>;
|
||||
groupSelectionsRef?: React.RefObject<DomEditSelection[]>;
|
||||
/** Studio's pointer handling, for the events that are not part of a marquee. */
|
||||
gestures?: {
|
||||
onPointerMove: (event: React.PointerEvent<HTMLDivElement>) => void;
|
||||
@@ -131,7 +138,7 @@ export interface MarqueeGesturesDeps<T = DomEditSelection> {
|
||||
}
|
||||
|
||||
export interface MarqueeGestures {
|
||||
marqueeRect: Rect | null;
|
||||
marqueeRect: MarqueeBand | null;
|
||||
candidateRects: Rect[];
|
||||
/** Starts a marquee at this press; the host has decided it landed on empty canvas. */
|
||||
begin: (event: React.PointerEvent<HTMLElement>) => void;
|
||||
@@ -161,7 +168,7 @@ export function useMarqueeGestures<T>(
|
||||
// fallow-ignore-next-line complexity
|
||||
export function useMarqueeGestures<T>(deps: MarqueeGesturesDeps<T>): MarqueeGestures {
|
||||
const marqueeRef = useRef<MarqueeState | null>(null);
|
||||
const [marqueeRect, setMarqueeRect] = useState<Rect | null>(null);
|
||||
const [marqueeRect, setMarqueeRect] = useState<MarqueeBand | null>(null);
|
||||
// Live "candidate" highlight: the elements the marquee currently touches,
|
||||
// shown before mouse-up so you can see what you're about to select. The
|
||||
// iframe DOM doesn't mutate during a drag, so a sync intersection per move
|
||||
@@ -171,10 +178,7 @@ export function useMarqueeGestures<T>(deps: MarqueeGesturesDeps<T>): MarqueeGest
|
||||
const candidatesRef = useRef<MarqueeHit[] | null>(null);
|
||||
|
||||
const commitMarquee = useCallback(
|
||||
async (
|
||||
rect: { left: number; top: number; width: number; height: number },
|
||||
additive: boolean,
|
||||
) => {
|
||||
async (rect: Rect, mode: MarqueeSelectionMode) => {
|
||||
const iframe = deps.iframeRef.current;
|
||||
const overlay = deps.overlayRef.current;
|
||||
if (!iframe || !overlay || !deps.onMarqueeSelectRef.current) return;
|
||||
@@ -187,7 +191,7 @@ export function useMarqueeGestures<T>(deps: MarqueeGesturesDeps<T>): MarqueeGest
|
||||
: ((await resolveDomEditSelections(elements, acp)) as T[]);
|
||||
const applySelection = deps.onMarqueeSelectRef.current;
|
||||
if (!applySelection) return;
|
||||
const result = applySelection(picks, additive);
|
||||
const result = applySelection(picks, mode);
|
||||
trackMarqueeSelection(result);
|
||||
},
|
||||
[
|
||||
@@ -244,16 +248,25 @@ export function useMarqueeGestures<T>(deps: MarqueeGesturesDeps<T>): MarqueeGest
|
||||
window.removeEventListener("keydown", cancelBandBeforeHostEscape, { capture: true });
|
||||
}, [cancel]);
|
||||
|
||||
const isSelectedElement = useCallback(
|
||||
(element: HTMLElement) =>
|
||||
deps.selectionRef?.current?.element === element ||
|
||||
(deps.groupSelectionsRef?.current ?? []).some((s) => s.element === element),
|
||||
[deps.selectionRef, deps.groupSelectionsRef],
|
||||
);
|
||||
|
||||
const showCandidates = useCallback(
|
||||
(rect: Rect) => {
|
||||
(rect: Rect, mode: MarqueeSelectionMode) => {
|
||||
const iframe = deps.iframeRef.current;
|
||||
const overlay = deps.overlayRef.current;
|
||||
if (!iframe || !overlay) return;
|
||||
const acp = deps.activeCompositionPathRef.current ?? "index.html";
|
||||
candidatesRef.current ??= collectMarqueeCandidates(iframe, overlay, acp);
|
||||
setCandidateRects(hitsWithin(rect, candidatesRef.current).map((h) => h.rect));
|
||||
let hits = hitsWithin(rect, candidatesRef.current);
|
||||
if (mode === "subtract") hits = hits.filter((h) => isSelectedElement(h.element));
|
||||
setCandidateRects(hits.map((h) => h.rect));
|
||||
},
|
||||
[deps.overlayRef, deps.iframeRef, deps.activeCompositionPathRef],
|
||||
[deps.overlayRef, deps.iframeRef, deps.activeCompositionPathRef, isSelectedElement],
|
||||
);
|
||||
|
||||
const onPointerMove = useCallback(
|
||||
@@ -278,8 +291,9 @@ export function useMarqueeGestures<T>(deps: MarqueeGesturesDeps<T>): MarqueeGest
|
||||
width: Math.abs(m.currentX - m.startX),
|
||||
height: Math.abs(m.currentY - m.startY),
|
||||
};
|
||||
setMarqueeRect(rect);
|
||||
showCandidates(rect);
|
||||
const mode = resolveMarqueeMode(event);
|
||||
setMarqueeRect({ ...rect, mode });
|
||||
showCandidates(rect, mode);
|
||||
return;
|
||||
}
|
||||
deps.gestures?.onPointerMove(event);
|
||||
@@ -300,10 +314,10 @@ export function useMarqueeGestures<T>(deps: MarqueeGesturesDeps<T>): MarqueeGest
|
||||
width: Math.abs(m.currentX - m.startX),
|
||||
height: Math.abs(m.currentY - m.startY),
|
||||
},
|
||||
event.shiftKey,
|
||||
resolveMarqueeMode(event),
|
||||
);
|
||||
} else {
|
||||
deps.onMarqueeSelectRef.current?.([], false);
|
||||
deps.onMarqueeSelectRef.current?.([], "replace");
|
||||
}
|
||||
reset();
|
||||
return;
|
||||
|
||||
@@ -329,7 +329,7 @@ describe("DomEditOverlay with canvasInput host", () => {
|
||||
const off = fixture({ selection: null });
|
||||
fire(off.overlay, "pointerdown");
|
||||
fire(off.overlay, "pointerup");
|
||||
expect(off.spies.onMarqueeSelect).toHaveBeenCalledWith([], false);
|
||||
expect(off.spies.onMarqueeSelect).toHaveBeenCalledWith([], "replace");
|
||||
act(() => root.unmount());
|
||||
const { spies, overlay } = fixture({ ...HOST, selection: null });
|
||||
fire(overlay, "pointerdown");
|
||||
|
||||
@@ -98,10 +98,16 @@ describe("marquee package export, driven by a host", () => {
|
||||
act(() => marquee().begin(at(1, 1)));
|
||||
expect(overlay.setPointerCapture).toHaveBeenCalledWith(7);
|
||||
act(() => marquee().onPointerMove(at(20, 20)));
|
||||
expect(marquee().marqueeRect).toEqual({ left: 1, top: 1, width: 19, height: 19 });
|
||||
expect(marquee().marqueeRect).toEqual({
|
||||
left: 1,
|
||||
top: 1,
|
||||
width: 19,
|
||||
height: 19,
|
||||
mode: "replace",
|
||||
});
|
||||
expect(marquee().candidateRects).toEqual([rects.get("a")]);
|
||||
await act(async () => marquee().onPointerUp(at(20, 20, true)));
|
||||
expect(onSelect).toHaveBeenCalledWith(["a"], true);
|
||||
expect(onSelect).toHaveBeenCalledWith(["a"], "add");
|
||||
expect(overlay.releasePointerCapture).toHaveBeenCalledWith(7);
|
||||
expect(marquee().marqueeRect).toBeNull();
|
||||
});
|
||||
@@ -120,7 +126,7 @@ describe("marquee package export, driven by a host", () => {
|
||||
const { onSelect, at, marquee } = mountMarquee<string>({ resolveHits });
|
||||
act(() => marquee().begin(at(1, 1)));
|
||||
await act(async () => marquee().onPointerUp(at(2, 2)));
|
||||
expect(onSelect).toHaveBeenCalledWith([], false);
|
||||
expect(onSelect).toHaveBeenCalledWith([], "replace");
|
||||
expect(resolveHits).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -167,7 +173,7 @@ describe("marquee package export, driven by a host", () => {
|
||||
document.getElementById("a"),
|
||||
expect.objectContaining({ skipSourceProbe: true }),
|
||||
);
|
||||
expect(onSelect).toHaveBeenCalledWith([{ id: "a" }], false);
|
||||
expect(onSelect).toHaveBeenCalledWith([{ id: "a" }], "replace");
|
||||
});
|
||||
|
||||
it("passes pointer events that are not a marquee to Studio's gestures, and needs none", () => {
|
||||
|
||||
@@ -137,7 +137,7 @@ describe("useDomSelection marquee", () => {
|
||||
it("announces every marquee'd element to the timeline, anchored on the primary", () => {
|
||||
const { harness, card, chip } = renderCardAndChip();
|
||||
|
||||
act(() => harness.current().applyMarqueeSelection([card, chip], false));
|
||||
act(() => harness.current().applyMarqueeSelection([card, chip], "replace"));
|
||||
|
||||
expect(harness.current().domEditGroupSelections).toHaveLength(2);
|
||||
expect(harness.timeline.setTimelineSelectionSet).toHaveBeenCalledWith(
|
||||
@@ -165,7 +165,7 @@ describe("useDomSelection marquee", () => {
|
||||
.current()
|
||||
.applyMarqueeSelection(
|
||||
[makeSelection("Canvas only", canvasOnly), makeSelection("Card", card)],
|
||||
false,
|
||||
"replace",
|
||||
),
|
||||
);
|
||||
|
||||
@@ -207,11 +207,11 @@ describe("useDomSelection additive", () => {
|
||||
] as const)("publishes the smaller set when %s", (_, shrink) => {
|
||||
const { harness, card, chip } = renderCardAndChip();
|
||||
|
||||
act(() => harness.current().applyMarqueeSelection([card, chip], false));
|
||||
act(() => harness.current().applyMarqueeSelection([card, chip], "replace"));
|
||||
act(() =>
|
||||
shrink === "toggle"
|
||||
? harness.current().applyDomSelection(chip, { additive: true })
|
||||
: harness.current().applyMarqueeSelection([card], false),
|
||||
: harness.current().applyMarqueeSelection([card], "replace"),
|
||||
);
|
||||
|
||||
expect(harness.current().domEditGroupSelections).toHaveLength(1);
|
||||
@@ -225,7 +225,7 @@ describe("useDomSelection additive", () => {
|
||||
it("keeps the live set when a single member is re-announced", () => {
|
||||
const { harness, card, chip } = renderCardAndChip();
|
||||
|
||||
act(() => harness.current().applyMarqueeSelection([card, chip], false));
|
||||
act(() => harness.current().applyMarqueeSelection([card, chip], "replace"));
|
||||
act(() => harness.current().applyDomSelection(chip));
|
||||
|
||||
expect(harness.timeline.setTimelineSelectionSet).toHaveBeenLastCalledWith(
|
||||
@@ -449,22 +449,103 @@ it("reports unchanged marquee membership and one new additive member", () => {
|
||||
act(() => harness.current().applyDomSelection(card));
|
||||
let receipt!: ReturnType<ReturnType<typeof useDomSelection>["applyMarqueeSelection"]>;
|
||||
act(() => {
|
||||
receipt = harness.current().applyMarqueeSelection([chip], true);
|
||||
receipt = harness.current().applyMarqueeSelection([chip], "add");
|
||||
});
|
||||
expect(receipt).toEqual({ changed: true, count: 2 });
|
||||
act(() => {
|
||||
receipt = harness.current().applyMarqueeSelection([card, chip], true);
|
||||
receipt = harness.current().applyMarqueeSelection([card, chip], "add");
|
||||
});
|
||||
expect(receipt).toEqual({ changed: false, count: 2 });
|
||||
act(() => {
|
||||
receipt = harness.current().applyMarqueeSelection([], true);
|
||||
receipt = harness.current().applyMarqueeSelection([], "add");
|
||||
});
|
||||
expect(receipt).toEqual({ changed: false, count: 2 });
|
||||
act(() => {
|
||||
receipt = harness.current().applyMarqueeSelection([], false);
|
||||
receipt = harness.current().applyMarqueeSelection([], "replace");
|
||||
});
|
||||
expect(receipt).toEqual({ changed: true, count: 0 });
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
describe("useDomSelection subtract", () => {
|
||||
it("drops the covered members and announces the smaller set", () => {
|
||||
const { harness, card, chip } = renderCardAndChip();
|
||||
try {
|
||||
act(() => harness.current().applyMarqueeSelection([card, chip], "replace"));
|
||||
let receipt!: ReturnType<ReturnType<typeof useDomSelection>["applyMarqueeSelection"]>;
|
||||
act(() => {
|
||||
receipt = harness.current().applyMarqueeSelection([chip], "subtract");
|
||||
});
|
||||
|
||||
expect(receipt).toEqual({ changed: true, count: 1 });
|
||||
expect(harness.current().domEditGroupSelections).toHaveLength(1);
|
||||
expect(harness.current().domEditSelection?.element).toBe(card.element);
|
||||
expect(harness.timeline.setTimelineSelectionSet).toHaveBeenLastCalledWith(new Set(["card"]));
|
||||
expect(harness.timeline.setSelectedTimelineElementId).toHaveBeenLastCalledWith("card", {
|
||||
preserveSet: true,
|
||||
});
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("re-anchors on a survivor when the primary is subtracted", () => {
|
||||
const { harness, card, chip } = renderCardAndChip();
|
||||
try {
|
||||
act(() => harness.current().applyMarqueeSelection([card, chip], "replace"));
|
||||
expect(harness.current().domEditSelection?.element).toBe(card.element);
|
||||
|
||||
act(() => harness.current().applyMarqueeSelection([card], "subtract"));
|
||||
|
||||
expect(harness.current().domEditSelection?.element).toBe(chip.element);
|
||||
expect(harness.current().domEditGroupSelections).toHaveLength(1);
|
||||
expect(harness.timeline.setSelectedTimelineElementId).toHaveBeenLastCalledWith("chip", {
|
||||
preserveSet: true,
|
||||
});
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("clears the selection when every member is subtracted", () => {
|
||||
const { harness, card, chip } = renderCardAndChip();
|
||||
try {
|
||||
act(() => harness.current().applyMarqueeSelection([card, chip], "replace"));
|
||||
let receipt!: ReturnType<ReturnType<typeof useDomSelection>["applyMarqueeSelection"]>;
|
||||
act(() => {
|
||||
receipt = harness.current().applyMarqueeSelection([chip, card], "subtract");
|
||||
});
|
||||
|
||||
expect(receipt).toEqual({ changed: true, count: 0 });
|
||||
expect(harness.current().domEditSelection).toBeNull();
|
||||
expect(harness.current().domEditGroupSelections).toHaveLength(0);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("leaves the selection alone when the band covers nothing or only outsiders", () => {
|
||||
const { harness, card, chip } = renderCardAndChip();
|
||||
const other = makeSelection(
|
||||
"Other",
|
||||
Object.assign(document.createElement("div"), { id: "other" }),
|
||||
);
|
||||
try {
|
||||
act(() => harness.current().applyMarqueeSelection([card], "replace"));
|
||||
let receipt!: ReturnType<ReturnType<typeof useDomSelection>["applyMarqueeSelection"]>;
|
||||
act(() => {
|
||||
receipt = harness.current().applyMarqueeSelection([], "subtract");
|
||||
});
|
||||
expect(receipt).toEqual({ changed: false, count: 1 });
|
||||
act(() => {
|
||||
receipt = harness.current().applyMarqueeSelection([chip, other], "subtract");
|
||||
});
|
||||
expect(receipt).toEqual({ changed: false, count: 1 });
|
||||
expect(harness.current().domEditSelection?.element).toBe(card.element);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,6 +22,7 @@ import { reapplyPositionEditsAfterSeek } from "../components/editor/manualEdits"
|
||||
import { holdScenesOf } from "../utils/sceneHold";
|
||||
import { useStudioTestHooks } from "./useStudioTestHooks";
|
||||
import { logSelect } from "../utils/selectDebug";
|
||||
import type { MarqueeSelectionMode } from "../utils/marqueeGeometry";
|
||||
import { announceTimelineSelection as announceSelectionToTimeline } from "./domSelectionTimelineMirror";
|
||||
import type {
|
||||
ApplyDomSelectionOptions,
|
||||
@@ -490,30 +491,41 @@ export function useDomSelection({
|
||||
|
||||
const applyMarqueeSelection = useCallback(
|
||||
// fallow-ignore-next-line complexity
|
||||
(selections: DomEditSelection[], additive: boolean) => {
|
||||
logSelect("marquee", { hits: selections.length, additive });
|
||||
(selections: DomEditSelection[], mode: MarqueeSelectionMode) => {
|
||||
logSelect("marquee", { hits: selections.length, mode });
|
||||
const current = domEditSelectionRef.current;
|
||||
const currentGroup = domEditGroupSelectionsRef.current;
|
||||
const previous = seedDomEditGroupWithSelection(currentGroup, current);
|
||||
const replace = mode === "replace";
|
||||
if (selections.length === 0) {
|
||||
const count = seedDomEditGroupWithSelection(currentGroup, current).length;
|
||||
if (!additive) applyDomSelection(null, { revealPanel: false });
|
||||
return { changed: !additive && count > 0, count: additive ? count : 0 };
|
||||
if (replace) applyDomSelection(null, { revealPanel: false });
|
||||
return { changed: replace && previous.length > 0, count: replace ? 0 : previous.length };
|
||||
}
|
||||
let nextGroup: DomEditSelection[];
|
||||
if (additive) {
|
||||
nextGroup = seedDomEditGroupWithSelection(currentGroup, current);
|
||||
let nextSelection: DomEditSelection | undefined;
|
||||
if (mode === "add") {
|
||||
nextGroup = previous;
|
||||
for (const s of selections) {
|
||||
if (!domEditSelectionInGroup(nextGroup, s)) nextGroup = [...nextGroup, s];
|
||||
}
|
||||
nextSelection = current ?? selections[0];
|
||||
} else if (mode === "subtract") {
|
||||
nextGroup = previous.filter((entry) => !domEditSelectionInGroup(selections, entry));
|
||||
if (nextGroup.length === 0) {
|
||||
applyDomSelection(null, { revealPanel: false });
|
||||
return { changed: previous.length > 0, count: 0 };
|
||||
}
|
||||
// Subtracting the primary re-anchors on the first survivor.
|
||||
nextSelection =
|
||||
current && domEditSelectionInGroup(nextGroup, current) ? current : nextGroup[0];
|
||||
} else {
|
||||
// Dedupe by target: select-as-unit collapses marquee'd members to one group.
|
||||
nextGroup = [];
|
||||
for (const s of selections) {
|
||||
if (!domEditSelectionInGroup(nextGroup, s)) nextGroup.push(s);
|
||||
}
|
||||
nextSelection = selections[0];
|
||||
}
|
||||
const nextSelection = additive && current ? current : selections[0];
|
||||
const previous = seedDomEditGroupWithSelection(currentGroup, current);
|
||||
const changed =
|
||||
previous.length !== nextGroup.length ||
|
||||
nextGroup.some((selection) => !domEditSelectionInGroup(previous, selection)) ||
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { Dispatch, MutableRefObject, SetStateAction } from "react";
|
||||
import type { DomEditSelection } from "../components/editor/domEditing";
|
||||
import type { SelectElementOptions, TimelineElement } from "../player";
|
||||
import type { RightPanelTab } from "../utils/studioHelpers";
|
||||
import type { MarqueeSelectionMode } from "../utils/marqueeGeometry";
|
||||
|
||||
export interface DomSelectionResult {
|
||||
changed: boolean;
|
||||
@@ -93,5 +94,8 @@ export interface UseDomSelectionReturn {
|
||||
selection: DomEditSelection,
|
||||
iframe?: HTMLIFrameElement | null,
|
||||
) => Promise<void>;
|
||||
applyMarqueeSelection: (selections: DomEditSelection[], additive: boolean) => DomSelectionResult;
|
||||
applyMarqueeSelection: (
|
||||
selections: DomEditSelection[],
|
||||
mode: MarqueeSelectionMode,
|
||||
) => DomSelectionResult;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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 && (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
data-marquee-mode={props.marqueeRect.mode}
|
||||
className="absolute pointer-events-none"
|
||||
style={{
|
||||
left: props.marqueeRect.left,
|
||||
top: props.marqueeRect.top,
|
||||
width: props.marqueeRect.width,
|
||||
height: props.marqueeRect.height,
|
||||
background: "var(--timeline-accent-fill)",
|
||||
border: "1px dashed var(--timeline-accent-border)",
|
||||
...(props.marqueeRect.mode === "subtract"
|
||||
? {
|
||||
background: "var(--timeline-danger-fill)",
|
||||
border: "1px dashed var(--timeline-danger)",
|
||||
}
|
||||
: {
|
||||
background: "var(--timeline-accent-fill)",
|
||||
border: "1px dashed var(--timeline-accent-border)",
|
||||
}),
|
||||
borderRadius: 2,
|
||||
zIndex: 70,
|
||||
}}
|
||||
|
||||
@@ -16,7 +16,7 @@ import type { TimelineEmptyState } from "./TimelineEmptyState";
|
||||
import type { TimelineProps } from "./TimelineTypes";
|
||||
import type { TimelineRangeSelection } from "./timelineEditing";
|
||||
import type { TimelineDropPlacement } from "./timelineCallbacks";
|
||||
import type { Rect } from "../../utils/marqueeGeometry";
|
||||
import type { MarqueeBand } from "../../utils/marqueeGeometry";
|
||||
import type { ResizingClipState } from "./useTimelineClipDrag";
|
||||
import type { TimelineLaneBaseProps } from "./timelineLaneProps";
|
||||
import type { TimelineLaneGapStrips } from "./useTimelineGapHighlights";
|
||||
@@ -50,7 +50,7 @@ export type TimelineCanvasState = Omit<
|
||||
majorTickInterval: number;
|
||||
tickFrameRate: number | undefined;
|
||||
rangeSelection: TimelineRangeSelection | null;
|
||||
marqueeRect: Rect | null;
|
||||
marqueeRect: MarqueeBand | null;
|
||||
resizingClip: ResizingClipState | null;
|
||||
isScrubbing: boolean;
|
||||
playheadRef: React.RefObject<HTMLDivElement | null>;
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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<string>;
|
||||
/** 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<string>, 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<string>;
|
||||
mode?: MarqueeSelectionMode;
|
||||
}): MarqueeSelectionResult {
|
||||
const subtract = input.mode === "subtract";
|
||||
const ids = new Set<string>(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;
|
||||
}
|
||||
|
||||
@@ -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<string>;
|
||||
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<string>; 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);
|
||||
}
|
||||
@@ -103,20 +103,31 @@ function renderHarness(sessionEpoch = 1) {
|
||||
|
||||
function dragMarquee(
|
||||
view: ReturnType<typeof renderHarness>,
|
||||
options: { secondPointer?: boolean; release?: boolean } = {},
|
||||
options: {
|
||||
secondPointer?: boolean;
|
||||
release?: boolean;
|
||||
down?: Partial<React.PointerEvent>;
|
||||
move?: Partial<React.PointerEvent>;
|
||||
} = {},
|
||||
): 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);
|
||||
|
||||
@@ -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<string>;
|
||||
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<string>; 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<MarqueeDragState | null>(null);
|
||||
const [marqueeRect, setMarqueeRect] = useState<Rect | null>(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<MarqueeBand | null>(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<MarqueePointer | null>(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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user