🎥 Make videos programmatically with React
`@remotion/studio`: Keep easing selection active while dragging
Jonny Burger5de48062ee9e
diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsxindex 0a645a7d90..f7f8d7d498 100644--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx@@ -546,7 +546,7 @@ export const getTimelineSelectionKey = (item: TimelineSelection): string => {case 'easing':return `${timelineNodePathInfoToKey(item.nodePathInfo)}.easing.${item.segmentIndex- }.${item.fromFrame}.${item.toFrame}`;+ }`;default:throw new Error(`Unexpected timeline selection type: ${item satisfies never}`,diff --git a/packages/studio/src/components/Timeline/use-timeline-keyframe-drag.ts b/packages/studio/src/components/Timeline/use-timeline-keyframe-drag.tsindex 353f31ba7a..e44ffd4436 100644--- a/packages/studio/src/components/Timeline/use-timeline-keyframe-drag.ts+++ b/packages/studio/src/components/Timeline/use-timeline-keyframe-drag.ts@@ -18,7 +18,11 @@ import {callMoveKeyframes} from './call-move-keyframe';import {findTrackForNodePathInfo} from './find-track-for-node-path-info';import {getBoundedKeyframeDragDelta} from './get-bounded-keyframe-drag-delta';import {parseKeyframeFieldFromNodePath} from './parse-keyframe-field-from-node-path';-import {useTimelineKeyframeDragState} from './TimelineKeyframeDragState';+import {+ getTimelineKeyframeDragKey,+ useTimelineKeyframeDragState,+ type TimelineDraggedKeyframe,+} from './TimelineKeyframeDragState';import {useCurrentTimelineSelectionStateAsRef,type TimelineEasingSelection,@@ -124,6 +128,69 @@ export const getKeyframesForTimelineEasingDrag = ({);};+export const getTimelineSelectionsAfterEasingKeyframeDrag = ({+ delta,+ selections,+ targets,+}: {+ readonly delta: number;+ readonly selections: readonly TimelineSelection[];+ readonly targets: readonly TimelineDraggedKeyframe[];+}): TimelineSelection[] => {+ const movedFrames = new Map(+ targets.map((target) => [+ getTimelineKeyframeDragKey(target),+ target.frame + delta,+ ]),+ );++ return selections.map((selection) => {+ if (selection.type === 'keyframe') {+ const movedFrame = movedFrames.get(+ getTimelineKeyframeDragKey({+ nodePathInfo: selection.nodePathInfo,+ frame: selection.frame,+ }),+ );++ return movedFrame === undefined+ ? selection+ : {+ ...selection,+ frame: movedFrame,+ };+ }++ if (selection.type === 'easing') {+ const movedFromFrame =+ movedFrames.get(+ getTimelineKeyframeDragKey({+ nodePathInfo: selection.nodePathInfo,+ frame: selection.fromFrame,+ }),+ ) ?? selection.fromFrame;+ const movedToFrame =+ movedFrames.get(+ getTimelineKeyframeDragKey({+ nodePathInfo: selection.nodePathInfo,+ frame: selection.toFrame,+ }),+ ) ?? selection.toFrame;++ return movedFromFrame === selection.fromFrame &&+ movedToFrame === selection.toFrame+ ? selection+ : {+ ...selection,+ fromFrame: movedFromFrame,+ toFrame: movedToFrame,+ };+ }++ return selection;+ });+};+const getCodeValueForTarget = ({propStatuses,nodePath,@@ -864,6 +931,17 @@ export const useTimelineEasingKeyframeDrag = ({return;}+ currentSelection.current.selectItems(+ getTimelineSelectionsAfterEasingKeyframeDrag({+ delta: lastDelta,+ selections: currentSelection.current.selectedItems,+ targets: targets.map((target) => ({+ nodePathInfo: target.nodePathInfo,+ frame: target.displayFrame,+ })),+ }),+ );+clearActiveOverrides();clearDraggedKeyframes();diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.tsindex 0564dabf0d..ecf02afcf1 100644--- a/packages/studio/src/test/timeline-selection.test.ts+++ b/packages/studio/src/test/timeline-selection.test.ts@@ -58,6 +58,7 @@ import {getTimelineMarqueeSelection,getTimelineSelectionAfterInteraction,getTimelineSelectionFromNodePathInfo,+ getTimelineSelectionKey,getTimelineSequenceSelectionKey,isTimelineSelectionModifierEvent,shouldSelectTimelineRowOnPointerDown,@@ -78,7 +79,10 @@ import {parseTransformOrigin,serializeTransformOrigin,} from '../components/Timeline/transform-origin-utils';-import {getKeyframesForTimelineEasingDrag} from '../components/Timeline/use-timeline-keyframe-drag';+import {+ getKeyframesForTimelineEasingDrag,+ getTimelineSelectionsAfterEasingKeyframeDrag,+} from '../components/Timeline/use-timeline-keyframe-drag';import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';import {loadEditorShowOutlinesOption,@@ -3259,6 +3263,65 @@ test('Dragging only selected easing segments drags connected keyframes', () => {]);});+test('Easing selection keys follow segment identity while frames move', () => {+ const nodePathInfo = makeNodePathInfo(['body', 0], ['controls', 'opacity']);++ expect(+ getTimelineSelectionKey({+ type: 'easing',+ nodePathInfo,+ fromFrame: 10,+ toFrame: 20,+ segmentIndex: 0,+ }),+ ).toBe(+ getTimelineSelectionKey({+ type: 'easing',+ nodePathInfo,+ fromFrame: 15,+ toFrame: 25,+ segmentIndex: 0,+ }),+ );+});++test('Easing keyframe drag preserves selected item types at moved frames', () => {+ const nodePathInfo = makeNodePathInfo(['body', 0], ['controls', 'opacity']);+ const selectedKeyframe = {+ type: 'keyframe' as const,+ nodePathInfo,+ frame: 10,+ };+ const selectedEasing = {+ type: 'easing' as const,+ nodePathInfo,+ fromFrame: 10,+ toFrame: 20,+ segmentIndex: 0,+ };++ expect(+ getTimelineSelectionsAfterEasingKeyframeDrag({+ delta: 5,+ selections: [selectedKeyframe, selectedEasing],+ targets: [+ {nodePathInfo, frame: 10},+ {nodePathInfo, frame: 20},+ ],+ }),+ ).toEqual([+ {+ ...selectedKeyframe,+ frame: 15,+ },+ {+ ...selectedEasing,+ fromFrame: 15,+ toFrame: 25,+ },+ ]);+});+test('Timeline double-click actions ignore selection modifier clicks', () => {expect(isTimelineSelectionModifierEvent({