mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-24 16:06:34 +00:00
fix(studio): keep every element a marquee caught, not just the first
The marquee built the group correctly and then threw it away. It announced only the primary to the timeline, and the timeline is the source of truth for what is selected: the sync back to the canvas saw one selected id against a group of several, decided the canvas was stale, and replaced the group with that single element a moment after the drop. Drag a box around four things, get one. The whole set is announced now, and the primary goes in as its anchor rather than as a new single selection, so the set it just joined survives. This is the same reason the single-select path already anchors with preserveSet. A test drives applyMarqueeSelection with two elements and asserts both reach the timeline; it fails against the old single-id announce.
This commit is contained in:
@@ -91,6 +91,7 @@ export function StudioApp() {
|
||||
const captionSync = useCaptionSync(projectId);
|
||||
const timelineElements = usePlayerStore((s) => s.elements);
|
||||
const setSelectedTimelineElementId = usePlayerStore((s) => s.setSelectedElementId);
|
||||
const setTimelineSelectionSet = usePlayerStore((s) => s.setSelectedElementIds);
|
||||
const timelineDuration = usePlayerStore((s) => s.duration);
|
||||
const isPlaying = usePlayerStore((s) => s.isPlaying);
|
||||
const isMasterView = !activeCompPath || activeCompPath === "index.html";
|
||||
@@ -277,6 +278,7 @@ export function StudioApp() {
|
||||
previewIframeRef,
|
||||
timelineElements,
|
||||
setSelectedTimelineElementId,
|
||||
setTimelineSelectionSet,
|
||||
setRightCollapsed: panelLayout.setRightCollapsed,
|
||||
setRightPanelTab: panelLayout.setRightPanelTab,
|
||||
showToast,
|
||||
|
||||
@@ -230,6 +230,7 @@ describe("onReorderShadow source filter", () => {
|
||||
previewIframeRef: { current: null },
|
||||
timelineElements: [],
|
||||
setSelectedTimelineElementId: vi.fn(),
|
||||
setTimelineSelectionSet: vi.fn(),
|
||||
setRightCollapsed: vi.fn(),
|
||||
setRightPanelTab: vi.fn(),
|
||||
showToast: vi.fn(),
|
||||
@@ -328,6 +329,7 @@ describe("bulk segment ease commits", () => {
|
||||
previewIframeRef: { current: null },
|
||||
timelineElements: [],
|
||||
setSelectedTimelineElementId: vi.fn(),
|
||||
setTimelineSelectionSet: vi.fn(),
|
||||
setRightCollapsed: vi.fn(),
|
||||
setRightPanelTab: vi.fn(),
|
||||
showToast: vi.fn(),
|
||||
|
||||
@@ -38,6 +38,7 @@ export interface UseDomEditSessionParams {
|
||||
previewIframeRef: React.MutableRefObject<HTMLIFrameElement | null>;
|
||||
timelineElements: TimelineElement[];
|
||||
setSelectedTimelineElementId: (id: string | null, options?: SelectElementOptions) => void;
|
||||
setTimelineSelectionSet: (ids: Set<string>) => void;
|
||||
setRightCollapsed: (collapsed: boolean) => void;
|
||||
setRightPanelTab: (tab: RightPanelTab) => void;
|
||||
showToast: (message: string, tone?: "error" | "info") => void;
|
||||
@@ -80,6 +81,7 @@ export function useDomEditSession({
|
||||
previewIframeRef,
|
||||
timelineElements,
|
||||
setSelectedTimelineElementId,
|
||||
setTimelineSelectionSet,
|
||||
setRightCollapsed,
|
||||
setRightPanelTab,
|
||||
showToast,
|
||||
@@ -137,6 +139,7 @@ export function useDomEditSession({
|
||||
previewIframeRef,
|
||||
timelineElements,
|
||||
setSelectedTimelineElementId,
|
||||
setTimelineSelectionSet,
|
||||
setRightCollapsed,
|
||||
setRightPanelTab,
|
||||
previewIframe,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { createRoot } from "react-dom/client";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { installReactActEnvironment, makeSelection } from "./domSelectionTestHarness";
|
||||
import { useDomSelection } from "./useDomSelection";
|
||||
import type { TimelineElement } from "../player";
|
||||
|
||||
installReactActEnvironment();
|
||||
|
||||
@@ -14,11 +15,24 @@ interface HarnessProps {
|
||||
refreshKey: number;
|
||||
}
|
||||
|
||||
function renderHarness(initialProps: HarnessProps): {
|
||||
interface TimelineSpies {
|
||||
setSelectedTimelineElementId: ReturnType<typeof vi.fn>;
|
||||
setTimelineSelectionSet: ReturnType<typeof vi.fn>;
|
||||
}
|
||||
|
||||
function renderHarness(
|
||||
initialProps: HarnessProps,
|
||||
options: { timelineElements?: TimelineElement[] } = {},
|
||||
): {
|
||||
current: () => ReturnType<typeof useDomSelection>;
|
||||
rerender: (props: HarnessProps) => void;
|
||||
cleanup: () => void;
|
||||
timeline: TimelineSpies;
|
||||
} {
|
||||
const timeline: TimelineSpies = {
|
||||
setSelectedTimelineElementId: vi.fn(),
|
||||
setTimelineSelectionSet: vi.fn(),
|
||||
};
|
||||
const host = document.createElement("div");
|
||||
document.body.append(host);
|
||||
const root = createRoot(host);
|
||||
@@ -32,8 +46,9 @@ function renderHarness(initialProps: HarnessProps): {
|
||||
compIdToSrc: new Map(),
|
||||
captionEditMode: false,
|
||||
previewIframeRef: { current: null },
|
||||
timelineElements: [],
|
||||
setSelectedTimelineElementId: vi.fn(),
|
||||
timelineElements: options.timelineElements ?? [],
|
||||
setSelectedTimelineElementId: timeline.setSelectedTimelineElementId,
|
||||
setTimelineSelectionSet: timeline.setTimelineSelectionSet,
|
||||
setRightCollapsed: vi.fn(),
|
||||
setRightPanelTab: vi.fn(),
|
||||
previewIframe: null,
|
||||
@@ -61,6 +76,7 @@ function renderHarness(initialProps: HarnessProps): {
|
||||
act(() => root.unmount());
|
||||
host.remove();
|
||||
},
|
||||
timeline,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -77,6 +93,58 @@ function setupSelectedHarness() {
|
||||
return { selection, harness };
|
||||
}
|
||||
|
||||
function timelineElement(domId: string): TimelineElement {
|
||||
return {
|
||||
id: domId,
|
||||
key: domId,
|
||||
domId,
|
||||
tag: "div",
|
||||
start: 0,
|
||||
duration: 1,
|
||||
track: 0,
|
||||
sourceFile: "index.html",
|
||||
} as TimelineElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* A marquee builds the group correctly and then used to lose it: it announced only
|
||||
* the primary to the timeline, the timeline is the source of truth for what is
|
||||
* selected, and the sync back to the canvas replaced the group with that one
|
||||
* element a moment after the drop. The whole set has to be announced, with the
|
||||
* primary as its anchor rather than as a new single selection.
|
||||
*/
|
||||
describe("useDomSelection marquee", () => {
|
||||
it("announces every marquee'd element to the timeline, anchored on the primary", () => {
|
||||
const first = document.createElement("div");
|
||||
first.id = "card";
|
||||
const second = document.createElement("div");
|
||||
second.id = "chip";
|
||||
document.body.append(first, second);
|
||||
const harness = renderHarness(
|
||||
{ activeCompPath: "index.html", projectId: "project-1", refreshKey: 0 },
|
||||
{ timelineElements: [timelineElement("card"), timelineElement("chip")] },
|
||||
);
|
||||
|
||||
act(() =>
|
||||
harness
|
||||
.current()
|
||||
.applyMarqueeSelection(
|
||||
[makeSelection("Card", first), makeSelection("Chip", second)],
|
||||
false,
|
||||
),
|
||||
);
|
||||
|
||||
expect(harness.current().domEditGroupSelections).toHaveLength(2);
|
||||
expect(harness.timeline.setTimelineSelectionSet).toHaveBeenCalledWith(
|
||||
new Set(["card", "chip"]),
|
||||
);
|
||||
expect(harness.timeline.setSelectedTimelineElementId).toHaveBeenCalledWith("card", {
|
||||
preserveSet: true,
|
||||
});
|
||||
harness.cleanup();
|
||||
});
|
||||
});
|
||||
|
||||
describe("useDomSelection", () => {
|
||||
it("clears a committed selection when the active composition path changes", () => {
|
||||
const { selection, harness } = setupSelectedHarness();
|
||||
|
||||
@@ -49,6 +49,8 @@ export interface UseDomSelectionParams {
|
||||
previewIframeRef: React.MutableRefObject<HTMLIFrameElement | null>;
|
||||
timelineElements: TimelineElement[];
|
||||
setSelectedTimelineElementId: (id: string | null, options?: SelectElementOptions) => void;
|
||||
/** Publishes a whole multi-selection to the timeline; the anchor is set separately. */
|
||||
setTimelineSelectionSet: (ids: Set<string>) => void;
|
||||
setRightCollapsed: (collapsed: boolean) => void;
|
||||
setRightPanelTab: (tab: RightPanelTab) => void;
|
||||
previewIframe: HTMLIFrameElement | null;
|
||||
@@ -111,6 +113,7 @@ export function useDomSelection({
|
||||
previewIframeRef,
|
||||
timelineElements,
|
||||
setSelectedTimelineElementId,
|
||||
setTimelineSelectionSet,
|
||||
setRightCollapsed,
|
||||
setRightPanelTab,
|
||||
previewIframe,
|
||||
@@ -535,16 +538,26 @@ export function useDomSelection({
|
||||
domEditGroupSelectionsRef.current = nextGroup;
|
||||
setDomEditSelection(nextSelection);
|
||||
setDomEditGroupSelections(nextGroup);
|
||||
const nextTimelineId =
|
||||
findMatchingTimelineElementId(nextSelection, timelineElements) ??
|
||||
// Publish the WHOLE set, not just the primary. The timeline is the source of
|
||||
// truth for what is selected, and the sync back to the canvas replaces the
|
||||
// canvas selection with whatever the timeline holds. Announcing one member
|
||||
// therefore un-selects every other one the marquee just caught, a moment
|
||||
// after the drop — the group is built correctly and then collapses to one.
|
||||
// The anchor goes second, and preserves the set it is now a member of.
|
||||
const timelineIdFor = (selection: DomEditSelection) =>
|
||||
findMatchingTimelineElementId(selection, timelineElements) ??
|
||||
findTimelineIdByAncestor(
|
||||
nextSelection.element,
|
||||
selection.element,
|
||||
timelineElements,
|
||||
nextSelection.sourceFile || "index.html",
|
||||
selection.sourceFile || "index.html",
|
||||
);
|
||||
setSelectedTimelineElementId(nextTimelineId);
|
||||
const nextTimelineId = timelineIdFor(nextSelection);
|
||||
setTimelineSelectionSet(
|
||||
new Set(nextGroup.map(timelineIdFor).filter((id): id is string => Boolean(id))),
|
||||
);
|
||||
setSelectedTimelineElementId(nextTimelineId, { preserveSet: true });
|
||||
},
|
||||
[applyDomSelection, timelineElements, setSelectedTimelineElementId],
|
||||
[applyDomSelection, timelineElements, setSelectedTimelineElementId, setTimelineSelectionSet],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user