🎥 Make videos programmatically with React
Share expanded timeline selection indexes
Jonny Burger92912819ba1c
diff --git a/packages/studio/src/components/Timeline/timeline-expanded-filter.ts b/packages/studio/src/components/Timeline/timeline-expanded-filter.tsindex 17ee9b2ea5..205f8cd27a 100644--- a/packages/studio/src/components/Timeline/timeline-expanded-filter.ts+++ b/packages/studio/src/components/Timeline/timeline-expanded-filter.ts@@ -1,3 +1,4 @@+import {stringifySequenceExpandedRowKey} from '@remotion/studio-shared';import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';import type {TimelineTreeNode} from '../../helpers/timeline-layout';import {timelineNodePathInfoToKey} from '../../helpers/timeline-node-path-key';@@ -37,20 +38,48 @@ export const filterTimelineExpandedTree = ({return out;};-export const getSelectedTimelineExpandedRowKeys = (+const selectedExpandedKeysByItems = new WeakMap<+ readonly TimelineSelection[],+ {+ readonly rowKeys: ReadonlySet<string>;+ readonly sourceKeys: ReadonlySet<string>;+ }+>();++export const getSelectedTimelineExpandedKeys = (selectedItems: readonly TimelineSelection[],-): ReadonlySet<string> => {- return new Set(- selectedItems.flatMap((item): string[] => {- if (item.type === 'guide') {- return [];- }+) => {+ const cached = selectedExpandedKeysByItems.get(selectedItems);+ if (cached !== undefined) {+ return cached;+ }- return [timelineNodePathInfoToKey(item.nodePathInfo)];- }),- );+ const rowKeys = new Set<string>();+ const sourceKeys = new Set<string>();+ selectedItems.forEach((item) => {+ if (item.type === 'guide') {+ return;+ }++ rowKeys.add(timelineNodePathInfoToKey(item.nodePathInfo));+ sourceKeys.add(+ stringifySequenceExpandedRowKey(+ item.nodePathInfo.sequenceSubscriptionKey,+ ),+ );+ });++ // Timeline rows share immutable selection snapshots. Weak keys release old selections.+ const keys = {rowKeys, sourceKeys};+ selectedExpandedKeysByItems.set(selectedItems, keys);+ return keys;};+export const getSelectedTimelineExpandedRowKeys = (+ selectedItems: readonly TimelineSelection[],+): ReadonlySet<string> =>+ getSelectedTimelineExpandedKeys(selectedItems).rowKeys;+export const isTimelineExpandedNodeSelected = ({nodePathInfo,selectedRowKeys,diff --git a/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts b/packages/studio/src/components/Timeline/use-timeline-expanded-tree.tsindex 90c57acca5..6e12281953 100644--- a/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts+++ b/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts@@ -11,6 +11,7 @@ import {import {getNodeHasKeyframes} from './get-node-keyframes';import {filterTimelineExpandedTree,+ getSelectedTimelineExpandedKeys,getSelectedTimelineExpandedRowKeys,isTimelineExpandedNodeSelected,} from './timeline-expanded-filter';@@ -34,8 +35,8 @@ export const useTimelineSequenceHasExpandableContent = ({const {getDragOverrides, getEffectDragOverrides} = useContext(Internals.VisualModeDragOverridesContext,);- const selectedRowKeys = useMemo(- () => getSelectedTimelineExpandedRowKeys(selectedItems),+ const {rowKeys: selectedRowKeys, sourceKeys: selectedSourceKeys} = useMemo(+ () => getSelectedTimelineExpandedKeys(selectedItems),[selectedItems],);const canHaveExpandableContent = useMemo(() => {@@ -45,15 +46,7 @@ export const useTimelineSequenceHasExpandableContent = ({const nodePath = nodePathInfo.sequenceSubscriptionKey;const sourceKey = stringifySequenceExpandedRowKey(nodePath);- if (- selectedItems.some(- (item) =>- item.type !== 'guide' &&- stringifySequenceExpandedRowKey(- item.nodePathInfo.sequenceSubscriptionKey,- ) === sourceKey,- )- ) {+ if (selectedSourceKeys.has(sourceKey)) {return true;}@@ -88,7 +81,7 @@ export const useTimelineSequenceHasExpandableContent = ({getDragOverrides,getEffectDragOverrides,nodePathInfo,- selectedItems,+ selectedSourceKeys,sequence.effects,visualModePropStatuses,]);