🎥 Make videos programmatically with React
Fix moving selected layers outside the current frame
Jonny Burger70cca6ee0ceb
diff --git a/packages/studio/src/components/SelectedOutlineKeyboardControls.tsx b/packages/studio/src/components/SelectedOutlineKeyboardControls.tsxindex 60e6bc9463..373002eb22 100644--- a/packages/studio/src/components/SelectedOutlineKeyboardControls.tsx+++ b/packages/studio/src/components/SelectedOutlineKeyboardControls.tsx@@ -15,31 +15,19 @@ import {type SelectedOutlineKeyframedDragChange,type SelectedOutlineStaticDragChange,} from './selected-outline-drag';-import type {getSequencesWithSelectableOutlines} from './selected-outline-measurement';-import {- getSelectedSequenceKeys,- getSequenceKeysContainingSelection,-} from './selected-outline-measurement';import {translateFieldKey,+ type SelectedOutlineDragTarget,type SelectedOutlineKeyboardNudgeSession,- type SelectedOutlineTarget,} from './selected-outline-types';import {callAddKeyframes} from './Timeline/call-add-keyframe';import {getCurrentDuration, getCurrentFps} from './Timeline/imperative-state';import {saveSequenceProps} from './Timeline/save-sequence-prop';import {ensureFrameIsInViewport} from './Timeline/timeline-scroll-logic';-import {useCurrentTimelineSelectionStateAsRef} from './Timeline/TimelineSelection';export const SelectedOutlineKeyboardControls: React.FC<{- readonly getLatestOutlineTargetByKey: (- key: string,- ) => SelectedOutlineTarget | undefined;- readonly getSelectableOutlines: () => ReturnType<- typeof getSequencesWithSelectableOutlines- >;-}> = ({getLatestOutlineTargetByKey, getSelectableOutlines}) => {- const currentSelection = useCurrentTimelineSelectionStateAsRef();+ readonly getAllDragTargets: () => readonly SelectedOutlineDragTarget[];+}> = ({getAllDragTargets}) => {const {getDragOverrides} = useContext(Internals.VisualModeDragOverridesContext,);@@ -206,24 +194,9 @@ export const SelectedOutlineKeyboardControls: React.FC<{return;}- const {selectedItems} = currentSelection.current;- const selectedSequenceKeys = getSelectedSequenceKeys(selectedItems);- const sequenceKeysContainingSelection =- getSequenceKeysContainingSelection(selectedItems);- const selectableOutlines = getSelectableOutlines();- const allDragTargets = selectableOutlines.flatMap(({key}) => {- if (- !selectedSequenceKeys.has(key) &&- !sequenceKeysContainingSelection.has(key)- ) {- return [];- }-- const drag = getLatestOutlineTargetByKey(key)?.drag ?? null;- return drag === null ? [] : [drag];- });+ const allDragTargets = getAllDragTargets();- if (selectedItems.length === 0 || allDragTargets.length === 0) {+ if (allDragTargets.length === 0) {seekWithArrowKey(event, direction);return;}@@ -299,11 +272,9 @@ export const SelectedOutlineKeyboardControls: React.FC<{}},[- currentSelection,+ getAllDragTargets,getCurrentFrame,getDragOverrides,- getLatestOutlineTargetByKey,- getSelectableOutlines,seekWithArrowKey,setDragOverrides,],diff --git a/packages/studio/src/components/SelectedOutlineOverlay.tsx b/packages/studio/src/components/SelectedOutlineOverlay.tsxindex fc081e495b..6b854158c4 100644--- a/packages/studio/src/components/SelectedOutlineOverlay.tsx+++ b/packages/studio/src/components/SelectedOutlineOverlay.tsx@@ -50,6 +50,7 @@ import {translateFieldKey,type SelectedOutlineCropDragTarget,type SelectedOutlineCropFieldKey,+ type SelectedOutlineDragTarget,type SelectedOutlineLayoutTarget,type SelectedOutlineTarget,} from './selected-outline-types';@@ -57,6 +58,7 @@ import {SelectedOutlineKeyboardControls} from './SelectedOutlineKeyboardControlsimport {SelectedOutlineRenderer} from './SelectedOutlineRenderer';import {getKeyframeDisplayOffset} from './Timeline/get-timeline-keyframes';import {+ useCurrentTimelineSelectionStateAsRef,useTimelineSelection,type TimelineSelection,type TimelineSelectionInteraction,@@ -668,6 +670,7 @@ type ActiveSelectedOutlineOverlayProps = Omit<> & {readonly calculateOutlineTargetsForCurrentState: CalculateOutlineTargets;readonly draggingOutline: boolean;+ readonly getAllDragTargets: () => readonly SelectedOutlineDragTarget[];readonly getLatestOutlineTargetByKey: (key: string,) => SelectedOutlineTarget | undefined;@@ -696,6 +699,7 @@ const ActiveSelectedOutlineOverlayUnmemoized: React.FC<compositionHeight,compositionWidth,draggingOutline,+ getAllDragTargets,getLatestOutlineTargetByKey,getSelectableOutlines,hoveredTimelineNodePathKey,@@ -804,6 +808,7 @@ const ActiveSelectedOutlineOverlayUnmemoized: React.FC<compositionHeight={compositionHeight}compositionWidth={compositionWidth}dragging={draggingOutline}+ getAllDragTargets={getAllDragTargets}getLatestOutlineTargetByKey={getLatestOutlineTargetByKey}outlineTargets={outlineTargets}onDraggingChange={onDraggingChange}@@ -831,6 +836,7 @@ const SelectedOutlineOverlayUnmemoized: React.FC<translationY,}) => {const {selectedItems, selectItem} = useTimelineSelection();+ const currentSelection = useCurrentTimelineSelectionStateAsRef();const {sequences} = useContext(Internals.SequenceManager);const {compositions} = useContext(Internals.CompositionManager);const {propStatuses} = useContext(Internals.VisualModePropStatusesContext);@@ -877,7 +883,7 @@ const SelectedOutlineOverlayUnmemoized: React.FC<[selectedItems],);const getSelectableOutlines = useCallback(- (timelinePosition: number) => {+ (timelinePosition: number | null) => {if (isFullscreen ||!isStudioSelectionEnabled() ||@@ -996,10 +1002,47 @@ const SelectedOutlineOverlayUnmemoized: React.FC<getSelectableOutlinesAtFrame,],);- const getCurrentSelectableOutlines = useCallback(- () => getSelectableOutlinesAtFrame(getCurrentFrame()),- [getCurrentFrame, getSelectableOutlinesAtFrame],- );+ const getAllDragTargets = useCallback((): SelectedOutlineDragTarget[] => {+ // Selected layers can be outside the current frame and have no mounted DOM.+ // Only outline measurement and snapping need to be restricted to visible layers.+ const selectedKeys = getSequenceKeysContainingSelection(+ currentSelection.current.selectedItems,+ );+ if (selectedKeys.size === 0) {+ return [];+ }++ const selectableOutlines = getSelectableOutlines(null).filter(({key}) =>+ selectedKeys.has(key),+ );+ const targets = calculateOutlineTargetsForCurrentState({+ mode: 'controls',+ runtimeValuesByStore: new Map(),+ selectableOutlines,+ targetKey: null,+ targetTimelinePosition: getCurrentFrame(),+ }) as SelectedOutlineTarget[];+ const dragTargets = new Map<string, SelectedOutlineDragTarget>();+ for (const {drag} of targets) {+ if (drag === null) {+ continue;+ }++ const sourceNodeKey = Internals.makeSequencePropsSubscriptionKey(+ drag.nodePath,+ );+ if (!dragTargets.has(sourceNodeKey)) {+ dragTargets.set(sourceNodeKey, drag);+ }+ }++ return [...dragTargets.values()];+ }, [+ calculateOutlineTargetsForCurrentState,+ currentSelection,+ getCurrentFrame,+ getSelectableOutlines,+ ]);const onDraggingChange = useCallback((dragging: boolean) => {setDraggingOutline(dragging);@@ -1039,10 +1082,7 @@ const SelectedOutlineOverlayUnmemoized: React.FC<return (<>- <SelectedOutlineKeyboardControls- getLatestOutlineTargetByKey={getLatestOutlineTargetByKey}- getSelectableOutlines={getCurrentSelectableOutlines}- />+ <SelectedOutlineKeyboardControls getAllDragTargets={getAllDragTargets} />{measurementActive ? (<ActiveSelectedOutlineOverlaycalculateOutlineTargetsForCurrentState={@@ -1051,6 +1091,7 @@ const SelectedOutlineOverlayUnmemoized: React.FC<compositionHeight={compositionHeight}compositionWidth={compositionWidth}draggingOutline={draggingOutline}+ getAllDragTargets={getAllDragTargets}getLatestOutlineTargetByKey={getLatestOutlineTargetByKey}getSelectableOutlines={getSelectableOutlines}hoveredTimelineNodePathKey={hoveredTimelineNodePathKey}diff --git a/packages/studio/src/components/SelectedOutlineRenderer.tsx b/packages/studio/src/components/SelectedOutlineRenderer.tsxindex 604acd8820..d3c1445a79 100644--- a/packages/studio/src/components/SelectedOutlineRenderer.tsx+++ b/packages/studio/src/components/SelectedOutlineRenderer.tsx@@ -20,6 +20,7 @@ import {import {orderOutlinesForRendering} from './selected-outline-order';import type {SelectedOutlineContextMenuOpenHandler,+ SelectedOutlineDragTarget,SelectedOutlineLayoutTarget,SelectedOutlineTarget,} from './selected-outline-types';@@ -51,6 +52,7 @@ const SelectedOutlineRendererUnmemoized: React.FC<{readonly compositionHeight: number;readonly compositionWidth: number;readonly dragging: boolean;+ readonly getAllDragTargets: () => readonly SelectedOutlineDragTarget[];readonly getLatestOutlineTargetByKey: (key: string,) => SelectedOutlineTarget | undefined;@@ -70,6 +72,7 @@ const SelectedOutlineRendererUnmemoized: React.FC<{compositionHeight,compositionWidth,dragging,+ getAllDragTargets,getLatestOutlineTargetByKey,outlineTargets,onDraggingChange,@@ -314,18 +317,6 @@ const SelectedOutlineRendererUnmemoized: React.FC<{targetsRef.current = outlineTargets;outlinesByKeyRef.current = outlinesByKey;}, [outlineTargets, outlinesByKey]);- const getAllDragTargets = useCallback(- () =>- targetsRef.current.flatMap((target) => {- if (!target.selected && !target.containsSelection) {- return [];- }-- const drag = getLatestOutlineTargetByKey(target.key)?.drag ?? null;- return drag === null ? [] : [drag];- }),- [getLatestOutlineTargetByKey],- );const getAllDragOutlines = useCallback(() =>targetsRef.current.flatMap((target) => {diff --git a/packages/studio/src/components/selected-outline-measurement.ts b/packages/studio/src/components/selected-outline-measurement.tsindex 04a06b83af..cc9e54f988 100644--- a/packages/studio/src/components/selected-outline-measurement.ts+++ b/packages/studio/src/components/selected-outline-measurement.ts@@ -606,7 +606,7 @@ export const getSequencesWithSelectableOutlines = ({readonly sequences: readonly TSequence[];readonly overrideIdsToNodePaths: OverrideIdToNodePaths;readonly compositions?: readonly _InternalTypes['AnyComposition'][];- readonly timelinePosition: number;+ readonly timelinePosition: number | null;}): SequenceWithSelectedOutline[] => {return calculateTimeline({sequences: [...sequences],@@ -620,8 +620,10 @@ export const getSequencesWithSelectableOutlines = ({return (track.sequence.showInTimeline &&- timelinePosition >= track.sequence.from &&- timelinePosition < track.sequence.from + track.sequence.duration &&+ (timelinePosition === null ||+ (timelinePosition >= track.sequence.from &&+ timelinePosition <+ track.sequence.from + track.sequence.duration)) &&track.nodePathInfo.auxiliaryKeys.length === 0);})