🎥 Make videos programmatically with React
Select the property after every keyframe deletion
Jonny Burgerb4411a07133a
diff --git a/packages/example/e2e/effect-keyframes.test.mts b/packages/example/e2e/effect-keyframes.test.mtsindex 7d310c261c..a054a9238d 100644--- a/packages/example/e2e/effect-keyframes.test.mts+++ b/packages/example/e2e/effect-keyframes.test.mts@@ -44,7 +44,7 @@ test.describe('effect keyframes', () => {await stopStudio();});- test('deletes marquee-selected keyframes without flashing and keeps their property selected', async ({+ test('deletes keyframes without flashing and keeps their property selected', async ({page,}) => {test.setTimeout(120_000);@@ -155,6 +155,60 @@ test.describe('effect keyframes', () => {.poll(() => fs.readFileSync(effectKeyframeE2eFile, 'utf-8')).toMatch(/interpolate\(\s*frame,\s*\[0,\s*30,\s*40,\s*60,\s*89\]/);+ // Single-keyframe deletion also selects the property, even at the playhead.+ await page+ .getByRole('button', {name: 'Go to next keyframe'})+ .last()+ .click();+ await page+ .getByRole('button', {name: 'Select keyframe at frame 30', exact: true})+ .click();+ await page.keyboard.press('Backspace');+ await expect+ .poll(() => fs.readFileSync(effectKeyframeE2eFile, 'utf-8'))+ .toMatch(/interpolate\(\s*frame,\s*\[0,\s*40,\s*60,\s*89\]/);+ await expect(+ page.getByTitle('Back to property', {exact: true}),+ ).toHaveCount(0);+ await expect(opacity).toHaveCount(2);++ // Removing from the keyframe inspector has the same result.+ await page+ .getByRole('button', {name: 'Go to next keyframe'})+ .last()+ .click();+ await page+ .getByRole('button', {name: 'Select keyframe at frame 40', exact: true})+ .click();+ await page+ .getByRole('button', {name: 'Remove keyframe', exact: true})+ .first()+ .click();+ await expect+ .poll(() => fs.readFileSync(effectKeyframeE2eFile, 'utf-8'))+ .toMatch(/interpolate\(\s*frame,\s*\[0,\s*60,\s*89\]/);+ await expect(+ page.getByTitle('Back to property', {exact: true}),+ ).toHaveCount(0);+ await expect(opacity).toHaveCount(2);++ // The timeline's keyframe toggle also keeps the property selected.+ await page+ .getByRole('button', {name: 'Go to next keyframe'})+ .last()+ .click();+ await page+ .getByRole('button', {name: 'Remove keyframe', exact: true})+ .last()+ .click();+ await expect+ .poll(() => fs.readFileSync(effectKeyframeE2eFile, 'utf-8'))+ .toMatch(/interpolate\(\s*frame,\s*\[0,\s*89\]/);+ await expect(+ page.getByTitle('Back to property', {exact: true}),+ ).toHaveCount(0);+ await expect(opacity).toHaveCount(2);+// The property remains selected, so another Backspace resets its value.await page.keyboard.press('Backspace');await expectdiff --git a/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx b/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsxindex 204871f20b..d4327cc918 100644--- a/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx+++ b/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx@@ -32,9 +32,7 @@ import {callDeleteSequenceKeyframe,} from '../Timeline/call-delete-keyframe';import {callMoveKeyframes} from '../Timeline/call-move-keyframe';-import {getEasingSelectionAfterKeyframeDelete} from '../Timeline/get-easing-selection-after-keyframe-delete';import {getKeyframeDisplayOffset} from '../Timeline/get-timeline-keyframes';-import {getCurrentFrame} from '../Timeline/imperative-state';import {parseKeyframeFieldFromNodePath} from '../Timeline/parse-keyframe-field-from-node-path';import {TimelineEffectPropValue} from '../Timeline/TimelineEffectPropItem';import {@@ -468,20 +466,7 @@ export const KeyframeInspector: React.FC<{return;}- const easingSelection = canEditEasingForInterpolationFunction(- details.propStatus.interpolationFunction,- )- ? getEasingSelectionAfterKeyframeDelete({- deletedSourceFrames: [details.sourceFrame],- keyframeDisplayOffset: details.keyframeDisplayOffset,- nodePathInfo: selection.nodePathInfo,- propStatus: details.propStatus,- timelinePosition: getCurrentFrame(),- })- : null;- if (easingSelection !== null) {- selectItems([easingSelection], {reveal: true});- } else if (parentSelection !== null) {+ if (parentSelection !== null) {selectItems([parentSelection], {reveal: true});}@@ -514,7 +499,6 @@ export const KeyframeInspector: React.FC<{parentSelection,previewServerState,selectItems,- selection.nodePathInfo,setPropStatuses,],);diff --git a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsxindex 179685e8bd..4e5a517a5f 100644--- a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx+++ b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx@@ -947,7 +947,6 @@ export const TimelineClipboardKeybindings: React.FC = () => {const nextSelection = getTimelineSelectionAfterDeletingItems({selections: selectedItems,- propStatuses,});if (nextSelection.length === 0) {clearSelection();diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsxindex 4588099b5e..b26f075316 100644--- a/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx+++ b/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx@@ -34,7 +34,6 @@ import {type DeleteEffectKeyframeChange,type DeleteSequenceKeyframeChange,} from './call-delete-keyframe';-import {getEasingSelectionAfterKeyframeDelete} from './get-easing-selection-after-keyframe-delete';import {getNextKeyframeDisplayFrame,getPreviousKeyframeDisplayFrame,@@ -54,7 +53,6 @@ import {useTimelineSelection,type TimelineSelection,} from './TimelineSelection';-import {canEditEasingForInterpolationFunction} from './update-selected-easing';const NAV_BUTTON_SIZE = 14;const INSPECTOR_NAV_BUTTON_WIDTH = NAV_BUTTON_SIZE / 2;@@ -737,23 +735,19 @@ export const TimelineKeyframeControls: React.FC<{const change = getDeleteChange(target);return change === null ? [] : [{target, change}];});- const singleDeleteTarget = deleteTargets[0];- const easingSelection =- deleteTargets.length === 1 &&- singleDeleteTarget &&- isKeyframedStatus(singleDeleteTarget.target.propStatus) &&- canEditEasingForInterpolationFunction(- singleDeleteTarget.target.propStatus.interpolationFunction,- )- ? getEasingSelectionAfterKeyframeDelete({- deletedSourceFrames: [singleDeleteTarget.target.sourceFrame],- keyframeDisplayOffset:- singleDeleteTarget.target.keyframeDisplayOffset,- nodePathInfo: singleDeleteTarget.target.nodePathInfo,- propStatus: singleDeleteTarget.target.propStatus,- timelinePosition,- })- : null;+ if (deleteTargets.length === 0) {+ return;+ }++ selectItems(+ deleteTargets.flatMap(({target}) => {+ const propertySelection = getTimelineSelectionFromNodePathInfo(+ target.nodePathInfo,+ );+ return propertySelection === null ? [] : [propertySelection];+ }),+ {reveal: true},+ );const deleteChanges = deleteTargets.map(({change}) => change);await callDeleteKeyframes({sequenceKeyframes: deleteChanges.filter(@@ -767,10 +761,6 @@ export const TimelineKeyframeControls: React.FC<{setPropStatuses,clientId,});- if (mode === 'timeline' && easingSelection !== null) {- selectItems([easingSelection], {reveal: true});- }-return;}@@ -818,7 +808,6 @@ export const TimelineKeyframeControls: React.FC<{mode,selectItems,setPropStatuses,- timelinePosition,],);diff --git a/packages/studio/src/components/Timeline/delete-selected-timeline-item.ts b/packages/studio/src/components/Timeline/delete-selected-timeline-item.tsindex 0e4a795a12..4e7ddc5f93 100644--- a/packages/studio/src/components/Timeline/delete-selected-timeline-item.ts+++ b/packages/studio/src/components/Timeline/delete-selected-timeline-item.ts@@ -1,5 +1,4 @@import type {OverrideIdToNodePaths, PropStatuses, TSequence} from 'remotion';-import {Internals} from 'remotion';import {canUseEffectOperations} from '../../helpers/browser-studio-operations';import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';import type {ConfirmationDialogFunction} from '../ConfirmationDialog-types';@@ -7,17 +6,12 @@ import {deleteJsxNodes} from '../delete-jsx-nodes-api';import {deleteEffects as deleteEffectsApi} from '../effect-operations-api';import {showNotification} from '../Notifications/NotificationCenter';import {deleteSelectedKeyframes} from './delete-selected-keyframe';-import {findTrackForNodePathInfo} from './find-track-for-node-path-info';-import {getEasingSelectionAfterKeyframeDelete} from './get-easing-selection-after-keyframe-delete';-import {getKeyframeDisplayOffset} from './get-timeline-keyframes';-import {parseKeyframeFieldFromNodePath} from './parse-keyframe-field-from-node-path';import type {SetPropStatuses} from './save-sequence-prop';import {getTimelineSelectionFromNodePathInfo,getTimelineSelectionKey,type TimelineSelection,} from './TimelineSelection';-import {canEditEasingForInterpolationFunction} from './update-selected-easing';const confirmDeletingDuplicatedSequences = (nodePathInfos: SequenceNodePathInfo[],@@ -177,141 +171,11 @@ const getSequenceSelectionAfterDeletingEffect = (};};-const getEasingSelectionAfterDeletingKeyframes = ({- selections,- sequences,- overrideIdsToNodePaths,- propStatuses,- timelinePosition,-}: {- readonly selections: readonly TimelineSelection[];- readonly sequences: TSequence[] | undefined;- readonly overrideIdsToNodePaths: OverrideIdToNodePaths | undefined;- readonly propStatuses: PropStatuses | undefined;- readonly timelinePosition: number | undefined;-}): TimelineSelection | null => {- if (- sequences === undefined ||- overrideIdsToNodePaths === undefined ||- propStatuses === undefined ||- timelinePosition === undefined- ) {- return null;- }-- const keyframeSelections = selections.filter(isKeyframeSelection);- if (keyframeSelections.length !== 1) {- return null;- }-- const [selection] = keyframeSelections;- if (!selection) {- return null;- }-- const field = parseKeyframeFieldFromNodePath(- selection.nodePathInfo.auxiliaryKeys,- );- if (field === null) {- return null;- }-- const track = findTrackForNodePathInfo({- sequences,- overrideIdsToNodePaths,- nodePathInfo: selection.nodePathInfo,- });- if (!track || !track.sequence.controls) {- return null;- }-- const nodePath = selection.nodePathInfo.sequenceSubscriptionKey;- if (field.type === 'sequence') {- const sequencePropStatus = Internals.getPropStatusesCtx(- propStatuses,- nodePath,- )?.[field.fieldKey];- if (- sequencePropStatus?.status !== 'keyframed' ||- !canEditEasingForInterpolationFunction(- sequencePropStatus.interpolationFunction,- )- ) {- return null;- }-- return getEasingSelectionAfterKeyframeDelete({- deletedSourceFrames: [- selection.frame -- getKeyframeDisplayOffset({- propStatus: sequencePropStatus,- keyframeDisplayOffset: track.keyframeDisplayOffset,- }),- ],- keyframeDisplayOffset: track.keyframeDisplayOffset,- nodePathInfo: selection.nodePathInfo,- propStatus: sequencePropStatus,- timelinePosition,- });- }-- const effectStatus = Internals.getEffectPropStatusesCtx({- propStatuses,- nodePath,- effectIndex: field.effectIndex,- });- const effectPropStatus =- effectStatus.type === 'can-update-effect'- ? effectStatus.props[field.fieldKey]- : null;- if (- effectPropStatus?.status !== 'keyframed' ||- !canEditEasingForInterpolationFunction(- effectPropStatus.interpolationFunction,- )- ) {- return null;- }-- return getEasingSelectionAfterKeyframeDelete({- deletedSourceFrames: [- selection.frame -- getKeyframeDisplayOffset({- propStatus: effectPropStatus,- keyframeDisplayOffset: track.keyframeDisplayOffset,- }),- ],- keyframeDisplayOffset: track.keyframeDisplayOffset,- nodePathInfo: selection.nodePathInfo,- propStatus: effectPropStatus,- timelinePosition,- });-};-export const getTimelineSelectionAfterDeletingItems = ({selections,- sequences,- overrideIdsToNodePaths,- propStatuses,- timelinePosition,}: {readonly selections: readonly TimelineSelection[];- readonly sequences?: TSequence[];- readonly overrideIdsToNodePaths?: OverrideIdToNodePaths;- readonly propStatuses?: PropStatuses;- readonly timelinePosition?: number;}): readonly TimelineSelection[] => {- const easingSelection = getEasingSelectionAfterDeletingKeyframes({- selections,- sequences,- overrideIdsToNodePaths,- propStatuses,- timelinePosition,- });- if (easingSelection !== null) {- return [easingSelection];- }-const nextSelections = new Map<string, TimelineSelection>();for (const selection of selections) {diff --git a/packages/studio/src/components/Timeline/get-easing-selection-after-keyframe-delete.ts b/packages/studio/src/components/Timeline/get-easing-selection-after-keyframe-delete.tsdeleted file mode 100644index 3769619e73..0000000000--- a/packages/studio/src/components/Timeline/get-easing-selection-after-keyframe-delete.ts+++ /dev/null@@ -1,48 +0,0 @@-import type {CanUpdateSequencePropStatusKeyframed} from 'remotion';-import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';-import {getKeyframeDisplayOffset as resolveKeyframeDisplayOffset} from './get-timeline-keyframes';-import type {TimelineEasingSelection} from './TimelineSelection';--export const getEasingSelectionAfterKeyframeDelete = ({- deletedSourceFrames,- keyframeDisplayOffset,- nodePathInfo,- propStatus,- timelinePosition,-}: {- readonly deletedSourceFrames: readonly number[];- readonly keyframeDisplayOffset: number;- readonly nodePathInfo: SequenceNodePathInfo;- readonly propStatus: CanUpdateSequencePropStatusKeyframed;- readonly timelinePosition: number;-}): TimelineEasingSelection | null => {- const resolvedKeyframeDisplayOffset = resolveKeyframeDisplayOffset({- propStatus,- keyframeDisplayOffset,- });- const deletedSourceFrameSet = new Set(deletedSourceFrames);- const remainingKeyframes = propStatus.keyframes.filter(- (keyframe) => !deletedSourceFrameSet.has(keyframe.frame),- );- const sourceFrame = timelinePosition - resolvedKeyframeDisplayOffset;-- for (let i = 0; i < remainingKeyframes.length - 1; i++) {- const keyframe = remainingKeyframes[i];- const nextKeyframe = remainingKeyframes[i + 1];- if (!keyframe || !nextKeyframe) {- continue;- }-- if (sourceFrame > keyframe.frame && sourceFrame < nextKeyframe.frame) {- return {- type: 'easing',- nodePathInfo,- fromFrame: keyframe.frame + resolvedKeyframeDisplayOffset,- toFrame: nextKeyframe.frame + resolvedKeyframeDisplayOffset,- segmentIndex: i,- };- }- }-- return null;-};diff --git a/packages/studio/src/components/Timeline/use-delete-timeline-items.ts b/packages/studio/src/components/Timeline/use-delete-timeline-items.tsindex b1af477f06..c7002e3eb2 100644--- a/packages/studio/src/components/Timeline/use-delete-timeline-items.ts+++ b/packages/studio/src/components/Timeline/use-delete-timeline-items.ts@@ -84,10 +84,6 @@ export const useDeleteTimelineItems = () => {const updateSelectionAfterDeletion = () => {const nextSelection = getTimelineSelectionAfterDeletingItems({selections: selectedItems,- sequences,- overrideIdsToNodePaths: overrideIdToNodePathMappings,- propStatuses,- timelinePosition,});if (nextSelection.length === 0) {clearSelection();diff --git a/packages/studio/src/test/easing-selection-after-keyframe-delete.test.ts b/packages/studio/src/test/easing-selection-after-keyframe-delete.test.tsdeleted file mode 100644index f30cc3b9bf..0000000000--- a/packages/studio/src/test/easing-selection-after-keyframe-delete.test.ts+++ /dev/null@@ -1,74 +0,0 @@-import {expect, test} from 'bun:test';-import type {- CanUpdateSequencePropStatusKeyframed,- SequenceNodePath,- SequencePropsSubscriptionKey,-} from 'remotion';-import {getEasingSelectionAfterKeyframeDelete} from '../components/Timeline/get-easing-selection-after-keyframe-delete';-import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';--const makeNodePathInfo = (- nodePath: SequenceNodePath,- auxiliaryKeys: string[],-): SequenceNodePathInfo => ({- sequenceSubscriptionKey: {- absolutePath: '/project/src/Comp.tsx',- nodePath,- sequenceKeys: ['from', 'durationInFrames'],- effectKeys: [],- videoConfigValues: null,- } satisfies SequencePropsSubscriptionKey,- auxiliaryKeys,- index: 0,- numberOfSequencesWithThisNodePath: 1,- supportsEffects: true,-});--const keyframedStatus = {- status: 'keyframed',- keyframeDisplayOffsetAdjustment: null,- interpolationFunction: 'interpolate',- keyframes: [- {frame: 0, value: 0},- {frame: 10, value: 0.5},- {frame: 20, value: 1},- ],- easing: [{type: 'linear'}, {type: 'linear'}],- clamping: {left: 'extend', right: 'extend'},- posterize: undefined,- output: undefined,-} satisfies CanUpdateSequencePropStatusKeyframed;--test('gets easing selection after deleting an in-between keyframe', () => {- const nodePathInfo = makeNodePathInfo(['body', 0], ['controls', 'opacity']);-- expect(- getEasingSelectionAfterKeyframeDelete({- deletedSourceFrames: [10],- keyframeDisplayOffset: 5,- nodePathInfo,- propStatus: keyframedStatus,- timelinePosition: 15,- }),- ).toEqual({- type: 'easing',- nodePathInfo,- fromFrame: 5,- toFrame: 25,- segmentIndex: 0,- });-});--test('does not select an easing after deleting an edge keyframe', () => {- const nodePathInfo = makeNodePathInfo(['body', 0], ['controls', 'opacity']);-- expect(- getEasingSelectionAfterKeyframeDelete({- deletedSourceFrames: [0],- keyframeDisplayOffset: 5,- nodePathInfo,- propStatus: keyframedStatus,- timelinePosition: 5,- }),- ).toBe(null);-});diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.tsindex 7e91c08982..dde49fc1d1 100644--- a/packages/studio/src/test/timeline-selection.test.ts+++ b/packages/studio/src/test/timeline-selection.test.ts@@ -8398,37 +8398,11 @@ test('Deleting selected sequences still clears selection', () => {).toEqual([]);});-test('Deleting selected keyframe selects remaining easing under playhead', () => {- const schema = {- opacity: {type: 'number', default: 1, hiddenFromList: false},- } satisfies InteractivitySchema;+test('Deleting a selected keyframe selects its property', () => {const opacityNodePathInfo = makeNodePathInfo(['body', 0],['controls', 'opacity'],);- const nodePath = opacityNodePathInfo.sequenceSubscriptionKey;- const propStatuses = {- [Internals.makeSequencePropsSubscriptionKey(nodePath)]: {- canUpdate: true,- props: {- opacity: {- status: 'keyframed',- keyframeDisplayOffsetAdjustment: null,- interpolationFunction: 'interpolate',- keyframes: [- {frame: 0, value: 0},- {frame: 10, value: 0.5},- {frame: 20, value: 1},- ],- easing: [{type: 'linear'}, {type: 'linear'}],- clamping: {left: 'extend', right: 'extend'},- posterize: undefined,- output: undefined,- },- },- effects: [],- },- } satisfies PropStatuses;expect(getTimelineSelectionAfterDeletingItems({@@ -8439,67 +8413,6 @@ test('Deleting selected keyframe selects remaining easing under playhead', () =>frame: 10,},],- sequences: [makeTimelineSequence({schema})],- overrideIdsToNodePaths: {override: nodePath},- propStatuses,- timelinePosition: 10,- }),- ).toEqual([- {- type: 'easing',- nodePathInfo: opacityNodePathInfo,- fromFrame: 0,- toFrame: 20,- segmentIndex: 0,- },- ]);-});--test('Deleting selected keyframe selects its property when playhead is not between remaining keyframes', () => {- const schema = {- opacity: {type: 'number', default: 1, hiddenFromList: false},- } satisfies InteractivitySchema;- const opacityNodePathInfo = makeNodePathInfo(- ['body', 0],- ['controls', 'opacity'],- );- const nodePath = opacityNodePathInfo.sequenceSubscriptionKey;- const propStatuses = {- [Internals.makeSequencePropsSubscriptionKey(nodePath)]: {- canUpdate: true,- props: {- opacity: {- status: 'keyframed',- keyframeDisplayOffsetAdjustment: null,- interpolationFunction: 'interpolate',- keyframes: [- {frame: 0, value: 0},- {frame: 10, value: 0.5},- {frame: 20, value: 1},- ],- easing: [{type: 'linear'}, {type: 'linear'}],- clamping: {left: 'extend', right: 'extend'},- posterize: undefined,- output: undefined,- },- },- effects: [],- },- } satisfies PropStatuses;-- expect(- getTimelineSelectionAfterDeletingItems({- selections: [- {- type: 'keyframe',- nodePathInfo: opacityNodePathInfo,- frame: 0,- },- ],- sequences: [makeTimelineSequence({schema})],- overrideIdsToNodePaths: {override: nodePath},- propStatuses,- timelinePosition: 0,}),).toEqual([{