From bdf9ba0ee68369ddfa19e7bb59b5432544970294 Mon Sep 17 00:00:00 2001 From: Vincent Yip Date: Thu, 5 Nov 2026 04:09:52 +0000 Subject: [PATCH] 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. --- .../src/components/editor/DomEditOverlay.tsx | 4 +- .../src/components/editor/MarqueeOverlay.tsx | 16 +- .../components/editor/marqueeCommit.test.tsx | 141 +++++++++++++++- .../src/components/editor/marqueeCommit.ts | 46 ++++-- .../editor/previewReadOnly.overlay.test.tsx | 2 +- .../studio/src/editorGesturesExports.test.tsx | 14 +- .../studio/src/hooks/useDomSelection.test.ts | 99 ++++++++++- packages/studio/src/hooks/useDomSelection.ts | 30 +++- .../studio/src/hooks/useDomSelectionTypes.ts | 6 +- .../studio/src/hooks/useStudioUrlState.ts | 5 +- .../useTimelineSelectionPreviewSync.test.tsx | 8 +- .../hooks/useTimelineSelectionPreviewSync.ts | 5 +- packages/studio/src/index.ts | 7 +- .../src/player/components/TimelineCanvas.tsx | 14 +- .../player/components/TimelineProvider.tsx | 4 +- .../player/components/timelineMarquee.test.ts | 68 ++++++++ .../src/player/components/timelineMarquee.ts | 22 ++- .../components/timelineMarqueeCommit.ts | 74 +++++++++ .../useTimelineRangeSelection.test.tsx | 102 +++++++++++- .../components/useTimelineRangeSelection.ts | 156 ++++++------------ packages/studio/src/styles/theme.css | 1 + .../studio/src/utils/marqueeGeometry.test.ts | 19 ++- packages/studio/src/utils/marqueeGeometry.ts | 20 +++ .../studio/src/utils/studioUrlState.test.ts | 2 +- 24 files changed, 690 insertions(+), 175 deletions(-) create mode 100644 packages/studio/src/player/components/timelineMarqueeCommit.ts diff --git a/packages/studio/src/components/editor/DomEditOverlay.tsx b/packages/studio/src/components/editor/DomEditOverlay.tsx index 6408546adf..a4a46af161 100644 --- a/packages/studio/src/components/editor/DomEditOverlay.tsx +++ b/packages/studio/src/components/editor/DomEditOverlay.tsx @@ -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, }); diff --git a/packages/studio/src/components/editor/MarqueeOverlay.tsx b/packages/studio/src/components/editor/MarqueeOverlay.tsx index df7da60111..7be9153f81 100644 --- a/packages/studio/src/components/editor/MarqueeOverlay.tsx +++ b/packages/studio/src/components/editor/MarqueeOverlay.tsx @@ -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) => (