Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Filter expanded timeline rows (#8535)

Jonny Burger669fcfcc0a5b
diff --git a/packages/example/e2e/lost-node-path.test.mts b/packages/example/e2e/lost-node-path.test.mts
deleted file mode 100644
index 223e219521..0000000000
--- a/packages/example/e2e/lost-node-path.test.mts
+++ /dev/null
@@ -1,135 +0,0 @@
-import fs from 'fs';
-import {expect, test} from '@playwright/test';
-import {EXPANDED_SIDEBAR_STATE, lostNodePathE2eFile} from './constants.mts';
-import {
- navigateToLostNodePathE2e,
- readStudioLogs,
- stripAnsi,
-} from './helpers.mts';
-import {startStudio, stopStudio} from './studio-server.mts';
-
-const getSequenceLine = (content: string): number => {
- const lineIndex = content
- .split('\n')
- .findIndex((line) => line.trim().startsWith('<Sequence'));
- expect(lineIndex).toBeGreaterThan(-1);
- return lineIndex + 1;
-};
-
-const applyIssue7393Refactor = (content: string): string => {
- if (content.includes('const t = tint')) {
- return content;
- }
-
- return content
- .replace(
- '\tconst memoizedEffects = Internals.useMemoizedEffectDefinitions([',
- "\tconst t = tint({color: 'green', amount: 1});\n\tconst memoizedEffects = Internals.useMemoizedEffectDefinitions([",
- )
- .replace("\t\ttint({color: 'green', amount: 1}),", '\t\tt,');
-};
-
-const stackAttribution = (line: number) => `LostNodePathRepro.tsx:${line}`;
-const expandTintSectionName = /^Expand (?:Tint|tint\(\)) section$/;
-const collapseTintSectionName = /^Collapse (?:Tint|tint\(\)) section$/;
-
-test.use({storageState: EXPANDED_SIDEBAR_STATE});
-
-test.describe('lost node path recovery', () => {
- test.beforeEach(async () => {
- await startStudio();
- });
-
- test.afterEach(async () => {
- await stopStudio();
- });
-
- test('recovers stack location and preserves expanded timeline state after refactor', async ({
- page,
- }) => {
- const originalContent = fs.readFileSync(lostNodePathE2eFile, 'utf-8');
- const initialLine = getSequenceLine(originalContent);
- const refactoredContent = applyIssue7393Refactor(originalContent);
- const refactoredLine = getSequenceLine(refactoredContent);
- expect(refactoredLine).toBeGreaterThan(initialLine);
-
- await navigateToLostNodePathE2e(page);
-
- await expect(
- page.getByText(stackAttribution(initialLine), {exact: true}).first(),
- ).toBeVisible({timeout: 30_000});
-
- const expandTrack = page.getByRole('button', {
- name: 'Expand track properties',
- });
- await expect(expandTrack).toBeVisible({timeout: 10_000});
- await expandTrack.click();
-
- const expandEffects = page.getByRole('button', {
- name: 'Expand Effects section',
- });
- await expect(expandEffects).toBeVisible({timeout: 10_000});
- await expandEffects.click();
-
- const expandTint = page.getByRole('button', {
- name: expandTintSectionName,
- });
- await expect(expandTint).toBeVisible({timeout: 10_000});
- await expandTint.click();
-
- await expect(
- page.getByRole('button', {name: 'Collapse track properties'}),
- ).toBeVisible();
- await expect(
- page.getByRole('button', {name: 'Collapse Effects section'}),
- ).toBeVisible();
- await expect(
- page.getByRole('button', {name: collapseTintSectionName}).first(),
- ).toBeVisible();
-
- const logCountBefore = readStudioLogs().length;
- fs.writeFileSync(lostNodePathE2eFile, refactoredContent);
-
- await expect
- .poll(
- () => {
- const newLogs = readStudioLogs().slice(logCountBefore).map(stripAnsi);
- return newLogs.some((log) => log.includes('Built in'));
- },
- {
- message:
- 'Expected webpack to rebuild after LostNodePathRepro.tsx refactor',
- timeout: 30_000,
- },
- )
- .toBe(true);
-
- await expect
- .poll(
- async () =>
- page
- .getByText(stackAttribution(refactoredLine), {exact: true})
- .first()
- .isVisible(),
- {
- message: `Expected timeline stack to update to ${stackAttribution(refactoredLine)}`,
- timeout: 30_000,
- },
- )
- .toBe(true);
-
- await expect(
- page.getByText(stackAttribution(initialLine), {exact: true}),
- ).toHaveCount(0);
-
- await expect(
- page.getByRole('button', {name: 'Collapse track properties'}),
- ).toBeVisible();
- await expect(
- page.getByRole('button', {name: 'Collapse Effects section'}),
- ).toBeVisible();
- await expect(
- page.getByRole('button', {name: collapseTintSectionName}).first(),
- ).toBeVisible();
- });
-});
diff --git a/packages/example/e2e/undo-redo-sync.test.mts b/packages/example/e2e/undo-redo-sync.test.mts
deleted file mode 100644
index 72ecaa4cd5..0000000000
--- a/packages/example/e2e/undo-redo-sync.test.mts
+++ /dev/null
@@ -1,109 +0,0 @@
-import fs from 'fs';
-import {expect, test} from '@playwright/test';
-import {
- EXPANDED_SIDEBAR_STATE,
- STUDIO_URL,
- newVideoFile,
-} from './constants.mts';
-import {startStudio, stopStudio} from './studio-server.mts';
-
-test.use({storageState: EXPANDED_SIDEBAR_STATE});
-
-test.describe('undo redo sync across tabs', () => {
- test.beforeEach(async () => {
- await startStudio();
- });
-
- test.afterEach(async () => {
- await stopStudio();
- });
-
- test('a new studio tab should receive the current undo/redo state', async ({
- browser,
- }) => {
- const originalContent = fs.readFileSync(newVideoFile, 'utf-8');
- expect(originalContent).not.toContain('playbackRate');
-
- // 1. Open the first tab and make a change to create undo state
- const context1 = await browser.newContext({
- storageState: EXPANDED_SIDEBAR_STATE,
- });
- const page1 = await context1.newPage();
- await page1.goto(`${STUDIO_URL}/NewVideo`);
- await expect(page1).toHaveURL(/NewVideo/, {timeout: 15_000});
-
- // Dismiss any error overlay
- await page1.waitForTimeout(2_000);
- await page1.evaluate(() => {
- const overlay = document.getElementById('remotion-error-overlay');
- if (overlay) {
- overlay.style.display = 'none';
- }
- });
-
- // 2. Click the expand arrow on the Video track
- const expandTrackButton = page1.locator(
- 'button[aria-label="Expand track properties"]:not([disabled])',
- );
- await expect(expandTrackButton).toBeVisible({timeout: 15_000});
- await expandTrackButton.click();
-
- // 3. Click the Playback rate input dragger
- const playbackRateLabel = page1
- .getByText('Playback rate', {exact: true})
- .first();
- await expect(playbackRateLabel).toBeVisible({timeout: 10_000});
-
- const dragger = playbackRateLabel
- .locator('xpath=ancestor::div[1]/..')
- .locator('button.__remotion_input_dragger');
- await dragger.click();
-
- // 4. Enter a new playback rate
- const input = page1.locator('input[type="number"]:focus');
- await expect(input).toBeVisible({timeout: 5_000});
- await input.fill('2');
- await input.press('Enter');
-
- // 5. Assert the file was updated
- await expect
- .poll(
- () => {
- const content = fs.readFileSync(newVideoFile, 'utf-8');
- return content.includes('playbackRate={2}');
- },
- {
- message:
- 'Expected NewVideo.tsx to contain "playbackRate" after prop edit',
- timeout: 10_000,
- },
- )
- .toBe(true);
-
- // 6. Assert that undo button is visible in the first tab
- const undoButton1 = page1.locator('button[title*="Undo"]');
- await expect(undoButton1).toBeVisible({timeout: 5_000});
-
- // 7. Open a second tab and verify it also shows undo button
- const context2 = await browser.newContext({
- storageState: EXPANDED_SIDEBAR_STATE,
- });
- const page2 = await context2.newPage();
- await page2.goto(`${STUDIO_URL}/NewVideo`);
- await expect(page2).toHaveURL(/NewVideo/, {timeout: 15_000});
-
- const undoButton2 = page2.locator('button[title*="Undo"]');
- await expect(undoButton2).toBeVisible({timeout: 10_000});
-
- // 8. Clean up: reset file to initial state
- await page1.waitForTimeout(2_000);
- fs.writeFileSync(newVideoFile, originalContent);
-
- // 9. Assert undo buttons disappear in both tabs
- await expect(undoButton1).not.toBeVisible({timeout: 15_000});
- await expect(undoButton2).not.toBeVisible({timeout: 15_000});
-
- await context1.close();
- await context2.close();
- });
-});
diff --git a/packages/example/e2e/undo-redo.test.mts b/packages/example/e2e/undo-redo.test.mts
deleted file mode 100644
index 7bfdd58e3f..0000000000
--- a/packages/example/e2e/undo-redo.test.mts
+++ /dev/null
@@ -1,130 +0,0 @@
-import fs from 'fs';
-import {expect, test} from '@playwright/test';
-import {
- EXPANDED_SIDEBAR_STATE,
- STUDIO_URL,
- newVideoFile,
-} from './constants.mts';
-import {startStudio, stopStudio} from './studio-server.mts';
-
-test.use({storageState: EXPANDED_SIDEBAR_STATE});
-
-test.describe('undo redo', () => {
- test.beforeEach(async () => {
- await startStudio();
- });
-
- test.afterEach(async () => {
- await stopStudio();
- });
-
- test('should undo and redo a playback rate change', async ({page}) => {
- const originalContent = fs.readFileSync(newVideoFile, 'utf-8');
- expect(originalContent).not.toContain('playbackRate');
-
- // 1. Navigate to the NewVideo composition
- await page.goto(`${STUDIO_URL}/NewVideo`);
- await expect(page).toHaveURL(/NewVideo/, {timeout: 15_000});
-
- // Dismiss any error overlay that may appear (video can't play in test)
- await page.waitForTimeout(2_000);
- await page.evaluate(() => {
- const overlay = document.getElementById('remotion-error-overlay');
- if (overlay) {
- overlay.style.display = 'none';
- }
- });
-
- // 2. Click the expand arrow on the Video track
- const expandTrackButton = page.locator(
- 'button[aria-label="Expand track properties"]:not([disabled])',
- );
- await expect(expandTrackButton).toBeVisible({timeout: 15_000});
- await expandTrackButton.click();
-
- // 3. Click the Playback rate input dragger
- const playbackRateLabel = page
- .getByText('Playback rate', {exact: true})
- .first();
- await expect(playbackRateLabel).toBeVisible({timeout: 10_000});
-
- const dragger = playbackRateLabel
- .locator('xpath=ancestor::div[1]/..')
- .locator('button.__remotion_input_dragger');
- await dragger.click();
-
- // 4. Enter a new playback rate
- const input = page.locator('input[type="number"]:focus');
- await expect(input).toBeVisible({timeout: 5_000});
- await input.fill('2');
- await input.press('Enter');
-
- // 5. Assert that NewVideo.tsx was updated with playbackRate
- await expect
- .poll(
- () => {
- const content = fs.readFileSync(newVideoFile, 'utf-8');
- return content.includes('playbackRate={2}');
- },
- {
- message:
- 'Expected NewVideo.tsx to contain "playbackRate" after prop edit',
- timeout: 10_000,
- },
- )
- .toBe(true);
-
- // 6. Assert that the undo button has appeared
- const undoButton = page.locator('button[title*="Undo"]');
- await expect(undoButton).toBeVisible({timeout: 5_000});
-
- // 7. Click the undo button
- await undoButton.click();
-
- // 8. Assert that the file has reverted (no more playbackRate)
- await expect
- .poll(
- () => {
- const content = fs.readFileSync(newVideoFile, 'utf-8');
- return content.includes('playbackRate');
- },
- {
- message:
- 'Expected NewVideo.tsx to NOT contain "playbackRate" after undo',
- timeout: 10_000,
- },
- )
- .toBe(false);
-
- // 9. Assert that the redo button has shown up
- const redoButton = page.locator('button[title*="Redo"]');
- await expect(redoButton).toBeVisible({timeout: 5_000});
-
- // 10. Click the redo button
- await redoButton.click();
-
- // 11. Assert that the file has changed again (playbackRate is back)
- await expect
- .poll(
- () => {
- const content = fs.readFileSync(newVideoFile, 'utf-8');
- return content.includes('playbackRate');
- },
- {
- message: 'Expected NewVideo.tsx to contain "playbackRate" after redo',
- timeout: 10_000,
- },
- )
- .toBe(true);
-
- // 12. Reset file to initial state (remove playbackRate prop)
- // Wait for the redo's file watcher event to be consumed before writing,
- // otherwise macOS fsevents may batch both writes into a single event
- await page.waitForTimeout(2_000);
- fs.writeFileSync(newVideoFile, originalContent);
-
- // 13. Assert that Undo + Redo have disappeared (external write clears the undo stack)
- await expect(undoButton).not.toBeVisible({timeout: 15_000});
- await expect(redoButton).not.toBeVisible({timeout: 15_000});
- });
-});
diff --git a/packages/studio/src/components/ExpandedTracksProvider.tsx b/packages/studio/src/components/ExpandedTracksProvider.tsx
index 874135cc05..a1e72646e5 100644
--- a/packages/studio/src/components/ExpandedTracksProvider.tsx
+++ b/packages/studio/src/components/ExpandedTracksProvider.tsx
@@ -2,17 +2,59 @@ import React, {createContext, useCallback, useMemo, useState} from 'react';
import type {SequencePropsSubscriptionKey} from 'remotion';
import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';
import {migrateExpandedTracksForSubscriptionKey} from '../helpers/migrate-expanded-tracks-for-subscription-key';
-import {
- loadPersistedBooleanMap,
- persistBooleanMap,
- toggleBooleanMapKey,
-} from '../helpers/persist-boolean-map';
import {timelineNodePathInfoToKey} from '../helpers/timeline-node-path-key';
const SESSION_STORAGE_KEY = 'remotion.editor.expandedTracks';
+const onlyCollapsedTrackValues = (
+ state: Record<string, boolean>,
+): Record<string, boolean> => {
+ const result: Record<string, boolean> = {};
+
+ for (const [key, value] of Object.entries(state)) {
+ if (value === false) {
+ result[key] = false;
+ }
+ }
+
+ return result;
+};
+
const loadExpandedTracks = () => {
- return loadPersistedBooleanMap(SESSION_STORAGE_KEY);
+ if (typeof window === 'undefined') {
+ return {};
+ }
+
+ try {
+ const raw = window.sessionStorage.getItem(SESSION_STORAGE_KEY);
+ if (raw === null) {
+ return {};
+ }
+
+ const parsed: unknown = JSON.parse(raw);
+ if (!parsed || typeof parsed !== 'object') {
+ return {};
+ }
+
+ return onlyCollapsedTrackValues(parsed as Record<string, boolean>);
+ } catch {
+ return {};
+ }
+};
+
+const persistExpandedTracks = (state: Record<string, boolean>): void => {
+ if (typeof window === 'undefined') {
+ return;
+ }
+
+ try {
+ window.sessionStorage.setItem(
+ SESSION_STORAGE_KEY,
+ JSON.stringify(onlyCollapsedTrackValues(state)),
+ );
+ } catch {
+ // Ignore quota errors or disabled storage.
+ }
};
export type GetIsExpanded = (nodePathInfo: SequenceNodePathInfo) => boolean;
@@ -22,6 +64,7 @@ type ExpandedTracksGetterContextValue = {
};
type ExpandedTracksSetterContextValue = {
+ readonly expandParentTracks: (nodePathInfo: SequenceNodePathInfo) => void;
readonly toggleTrack: (nodePathInfo: SequenceNodePathInfo) => void;
readonly migrateExpandedTracksForSubscriptionKey: (
oldKey: SequencePropsSubscriptionKey,
@@ -38,6 +81,9 @@ export const ExpandedTracksGetterContext =
export const ExpandedTracksSetterContext =
createContext<ExpandedTracksSetterContextValue>({
+ expandParentTracks: () => {
+ throw new Error('ExpandedTracksSetterContext not initialized');
+ },
toggleTrack: () => {
throw new Error('ExpandedTracksSetterContext not initialized');
},
@@ -52,11 +98,57 @@ export const ExpandedTracksProvider: React.FC<{
const [expandedTracks, setExpandedTracks] =
useState<Record<string, boolean>>(loadExpandedTracks);
+ const expandParentTracks = useCallback(
+ (nodePathInfo: SequenceNodePathInfo) => {
+ const keysToExpand: string[] = [];
+
+ for (let i = 0; i < nodePathInfo.auxiliaryKeys.length; i++) {
+ keysToExpand.push(
+ timelineNodePathInfoToKey({
+ ...nodePathInfo,
+ auxiliaryKeys: nodePathInfo.auxiliaryKeys.slice(0, i),
+ }),
+ );
+ }
+
+ if (keysToExpand.length === 0) {
+ return;
+ }
+
+ setExpandedTracks((prev) => {
+ let changed = false;
+ const next = {...prev};
+
+ for (const key of keysToExpand) {
+ if (next[key] === false) {
+ delete next[key];
+ changed = true;
+ }
+ }
+
+ if (!changed) {
+ return prev;
+ }
+
+ persistExpandedTracks(next);
+ return next;
+ });
+ },
+ [],
+ );
+
const toggleTrack = useCallback((nodePathInfo: SequenceNodePathInfo) => {
setExpandedTracks((prev) => {
const key = timelineNodePathInfoToKey(nodePathInfo);
- const next = toggleBooleanMapKey(prev, key);
- persistBooleanMap(SESSION_STORAGE_KEY, next);
+ const next = {...prev};
+ const isExpanded = next[key] ?? true;
+ if (isExpanded) {
+ next[key] = false;
+ } else {
+ delete next[key];
+ }
+
+ persistExpandedTracks(next);
return next;
});
}, []);
@@ -76,7 +168,7 @@ export const ExpandedTracksProvider: React.FC<{
return prev;
}
- persistBooleanMap(SESSION_STORAGE_KEY, next);
+ persistExpandedTracks(next);
return next;
});
},
@@ -86,17 +178,18 @@ export const ExpandedTracksProvider: React.FC<{
const getterValue = useMemo(
(): ExpandedTracksGetterContextValue => ({
getIsExpanded: (nodePathInfo) =>
- expandedTracks[timelineNodePathInfoToKey(nodePathInfo)] ?? false,
+ expandedTracks[timelineNodePathInfoToKey(nodePathInfo)] ?? true,
}),
[expandedTracks],
);
const setterValue = useMemo(
(): ExpandedTracksSetterContextValue => ({
+ expandParentTracks,
toggleTrack,
migrateExpandedTracksForSubscriptionKey: migrateExpandedTracks,
}),
- [toggleTrack, migrateExpandedTracks],
+ [expandParentTracks, toggleTrack, migrateExpandedTracks],
);
return (
diff --git a/packages/studio/src/components/Timeline/TimelineExpandArrowButton.tsx b/packages/studio/src/components/Timeline/TimelineExpandArrowButton.tsx
index 3e401da86c..f862609766 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandArrowButton.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandArrowButton.tsx
@@ -32,6 +32,25 @@ export const TimelineExpandArrowButton: React.FC<{
readonly label: string;
readonly disabled: boolean;
}> = ({isExpanded, onClick, label, disabled = false}) => {
+ const handleClick = React.useCallback(
+ (e: React.MouseEvent<HTMLButtonElement>) => {
+ e.stopPropagation();
+ onClick();
+ },
+ [onClick],
+ );
+
+ const stopPropagation = React.useCallback(
+ (
+ e:
+ | React.MouseEvent<HTMLButtonElement>
+ | React.PointerEvent<HTMLButtonElement>,
+ ) => {
+ e.stopPropagation();
+ },
+ [],
+ );
+
const style: React.CSSProperties = useMemo(() => {
return {
...arrowButton,
@@ -45,7 +64,9 @@ export const TimelineExpandArrowButton: React.FC<{
<button
type="button"
style={style}
- onClick={onClick}
+ onClick={handleClick}
+ onDoubleClick={stopPropagation}
+ onPointerDown={stopPropagation}
disabled={disabled}
aria-expanded={isExpanded}
aria-label={`${isExpanded ? 'Collapse' : 'Expand'} ${label}`}
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
index 8006ea832f..3553561190 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
@@ -5,7 +5,7 @@ import {TIMELINE_TRACK_SEPARATOR} from '../../helpers/colors';
import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
import {
flattenVisibleTreeNodes,
- getExpandedTrackHeight,
+ getTreeRowHeight,
} from '../../helpers/timeline-layout';
import {TimelineExpandedRow} from './TimelineExpandedRow';
import {useTimelineExpandedTree} from './use-timeline-expanded-tree';
@@ -37,27 +37,24 @@ export const TimelineExpandedSection: React.FC<{
nestedDepth,
keyframeDisplayOffset,
}) => {
- const {getIsExpanded, propStatuses, toggleTrack, tree} =
- useTimelineExpandedTree({
- sequence,
- nodePathInfo,
- });
+ const {filteredTree, getIsExpanded, toggleTrack} = useTimelineExpandedTree({
+ sequence,
+ nodePathInfo,
+ });
const flat = useMemo(
- () => flattenVisibleTreeNodes({nodes: tree, getIsExpanded}),
- [tree, getIsExpanded],
+ () => flattenVisibleTreeNodes({nodes: filteredTree, getIsExpanded}),
+ [filteredTree, getIsExpanded],
);
- const expandedHeight = useMemo(
- () =>
- getExpandedTrackHeight({
- sequence,
- nodePathInfo,
- getIsExpanded,
- propStatuses,
- }),
- [sequence, nodePathInfo, getIsExpanded, propStatuses],
- );
+ const expandedHeight = useMemo(() => {
+ const totalRowsHeight = flat.reduce(
+ (sum, {node}) => sum + getTreeRowHeight(node),
+ 0,
+ );
+ const separators = Math.max(0, flat.length - 1);
+ return totalRowsHeight + separators;
+ }, [flat]);
const style = useMemo(() => {
return {
@@ -69,7 +66,7 @@ export const TimelineExpandedSection: React.FC<{
const {schema} = sequence.controls!;
if (flat.length === 0) {
- return <div style={style}>No schema</div>;
+ return null;
}
return (
diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsx
index 1b61b2765f..57c76cbe9c 100644
--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx
@@ -20,6 +20,7 @@ import {TIMELINE_PADDING} from '../../helpers/timeline-layout';
import {timelineNodePathInfoToKey} from '../../helpers/timeline-node-path-key';
import {useKeybinding} from '../../helpers/use-keybinding';
import {useZIndex} from '../../state/z-index';
+import {ExpandedTracksSetterContext} from '../ExpandedTracksProvider';
import {TimelineClipboardKeybindings} from './TimelineClipboardKeybindings';
import {TimelineDeleteKeybindings} from './TimelineDeleteKeybindings';
@@ -719,6 +720,7 @@ export const TimelineSelectionProvider: React.FC<{
const {canvasContent} = useContext(Internals.CompositionManager);
const timelineSelectionScope =
canvasContent?.type === 'composition' ? canvasContent.compositionId : null;
+ const {expandParentTracks} = useContext(ExpandedTracksSetterContext);
const canSelect =
previewServerState.type === 'connected' &&
!window.remotion_isReadOnlyStudio;
@@ -742,11 +744,6 @@ export const TimelineSelectionProvider: React.FC<{
);
const registrationCounter = useRef(0);
const marqueeRegistrationCounter = useRef(0);
- const [selectableItemsVersion, setSelectableItemsVersion] = useState(0);
-
- const bumpSelectableItemsVersion = useCallback(() => {
- setSelectableItemsVersion((version) => version + 1);
- }, []);
useEffect(() => {
if (!canSelect) {
@@ -767,14 +764,10 @@ export const TimelineSelectionProvider: React.FC<{
return EMPTY_TIMELINE_SELECTION_STATE;
}
- return getAvailableTimelineSelectionState({
- availableKeys: new Set(selectableItems.current.keys()),
- availableItemsByKey: selectableItems.current,
- state: {
- selectedItems: currentSelectedItems,
- anchor: selectionAnchor.current,
- },
- });
+ return {
+ selectedItems: currentSelectedItems,
+ anchor: selectionAnchor.current,
+ };
},
[timelineSelectionScope],
);
@@ -783,18 +776,38 @@ export const TimelineSelectionProvider: React.FC<{
getCurrentAvailableSelectionState(selectedItems);
const availableSelectedItems = availableSelectionState.selectedItems;
+ const expandParentsForSelectionItems = useCallback(
+ (items: readonly TimelineSelection[]) => {
+ for (const item of items) {
+ if (item.type === 'guide') {
+ continue;
+ }
+
+ expandParentTracks(item.nodePathInfo);
+ }
+ },
+ [expandParentTracks],
+ );
+
+ const expandParentsForSelectionItem = useCallback(
+ (item: TimelineSelection) => {
+ if (item.type === 'guide') {
+ return;
+ }
+
+ expandParentTracks(item.nodePathInfo);
+ },
+ [expandParentTracks],
+ );
+
useEffect(() => {
setSelectedItems((currentSelectedItems) => {
const nextState =
selectionScope.current === timelineSelectionScope
- ? getAvailableTimelineSelectionState({
- availableKeys: new Set(selectableItems.current.keys()),
- availableItemsByKey: selectableItems.current,
- state: {
- selectedItems: currentSelectedItems,
- anchor: selectionAnchor.current,
- },
- })
+ ? {
+ selectedItems: currentSelectedItems,
+ anchor: selectionAnchor.current,
+ }
: EMPTY_TIMELINE_SELECTION_STATE;
selectionScope.current = timelineSelectionScope;
@@ -811,7 +824,7 @@ export const TimelineSelectionProvider: React.FC<{
return nextState.selectedItems;
});
- }, [selectableItemsVersion, timelineSelectionScope]);
+ }, [timelineSelectionScope]);
const selectedKeys = useMemo(
() => new Set(availableSelectedItems.map(getTimelineSelectionKey)),
@@ -837,6 +850,8 @@ export const TimelineSelectionProvider: React.FC<{
return;
}
+ expandParentsForSelectionItem(item);
+
setSelectedItems((currentSelectedItems) => {
const currentSelectionState =
getCurrentAvailableSelectionState(currentSelectedItems);
@@ -864,7 +879,12 @@ export const TimelineSelectionProvider: React.FC<{
return nextState.selectedItems;
});
},
- [canSelectItem, getCurrentAvailableSelectionState, timelineSelectionScope],
+ [
+ canSelectItem,
+ expandParentsForSelectionItem,
+ getCurrentAvailableSelectionState,
+ timelineSelectionScope,
+ ],
);
const selectItems = useCallback(
@@ -876,48 +896,44 @@ export const TimelineSelectionProvider: React.FC<{
selectionScope.current = timelineSelectionScope;
selectionAnchor.current =
items.length === 0 ? null : items[items.length - 1];
+ expandParentsForSelectionItems(items);
setSelectedItems(items);
},
- [canSelectItem, timelineSelectionScope],
+ [canSelectItem, expandParentsForSelectionItems, timelineSelectionScope],
);
- const registerSelectableItem = useCallback(
- (item: TimelineSelection) => {
- const key = getTimelineSelectionKey(item);
- const currentRegistrationCount =
- selectableItemRegistrationCounts.current.get(key) ?? 0;
- if (currentRegistrationCount === 0) {
- const registrationOrder = registrationCounter.current;
- registrationCounter.current += 1;
- selectableItemsOrder.current.set(key, registrationOrder);
- }
+ const registerSelectableItem = useCallback((item: TimelineSelection) => {
+ const key = getTimelineSelectionKey(item);
+ const currentRegistrationCount =
+ selectableItemRegistrationCounts.current.get(key) ?? 0;
+ if (currentRegistrationCount === 0) {
+ const registrationOrder = registrationCounter.current;
+ registrationCounter.current += 1;
+ selectableItemsOrder.current.set(key, registrationOrder);
+ }
- selectableItemRegistrationCounts.current.set(
- key,
- currentRegistrationCount + 1,
- );
- selectableItems.current.set(key, item);
- bumpSelectableItemsVersion();
+ selectableItemRegistrationCounts.current.set(
+ key,
+ currentRegistrationCount + 1,
+ );
+ selectableItems.current.set(key, item);
- return () => {
- const nextRegistrationCount =
- (selectableItemRegistrationCounts.current.get(key) ?? 1) - 1;
- if (nextRegistrationCount > 0) {
- selectableItemRegistrationCounts.current.set(
- key,
- nextRegistrationCount,
- );
- return;
- }
+ return () => {
+ const nextRegistrationCount =
+ (selectableItemRegistrationCounts.current.get(key) ?? 1) - 1;
+ if (nextRegistrationCount > 0) {
+ selectableItemRegistrationCounts.current.set(
+ key,
+ nextRegistrationCount,
+ );
+ return;
+ }
- selectableItemRegistrationCounts.current.delete(key);
- selectableItems.current.delete(key);
- selectableItemsOrder.current.delete(key);
- bumpSelectableItemsVersion();
- };
- },
- [bumpSelectableItemsVersion],
- );
+ selectableItemRegistrationCounts.current.delete(key);
+ selectableItems.current.delete(key);
+ selectableItemsOrder.current.delete(key);
+ };
+ }, []);
const registerMarqueeSelectableItem = useCallback(
(item: TimelineSelection, getRect: () => DOMRect | null) => {
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
index 0268939dde..4bd437c5ba 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
@@ -50,6 +50,7 @@ import {
import {TimelineSequenceName} from './TimelineSequenceName';
import {useOpenSequenceInEditor} from './use-open-sequence-in-editor';
import {useSequenceFreezeFrameMenuItem} from './use-sequence-freeze-frame-menu-item';
+import {useTimelineExpandedTree} from './use-timeline-expanded-tree';
const labelContainerStyle: React.CSSProperties = {
alignItems: 'center',
@@ -77,6 +78,32 @@ type SequenceReorderDragData = {
let currentSequenceDrag: SequenceReorderDragData | null = null;
+const TimelineSequenceExpandArrow: React.FC<{
+ readonly disabled: boolean;
+ readonly isExpanded: boolean;
+ readonly nodePathInfo: SequenceNodePathInfo;
+ readonly onToggleExpand: () => void;
+ readonly sequence: TSequence;
+}> = ({disabled, isExpanded, nodePathInfo, onToggleExpand, sequence}) => {
+ const {filteredTree} = useTimelineExpandedTree({
+ sequence,
+ nodePathInfo,
+ });
+
+ if (filteredTree.length === 0) {
+ return <TimelineExpandArrowSpacer />;
+ }
+
+ return (
+ <TimelineExpandArrowButton
+ isExpanded={isExpanded}
+ onClick={onToggleExpand}
+ label="track properties"
+ disabled={disabled}
+ />
+ );
+};
+
const sequenceReorderWrapper: React.CSSProperties = {
position: 'relative',
};
@@ -981,12 +1008,13 @@ export const TimelineSequenceItem: React.FC<{
)
}
arrow={
- hasExpandableContent ? (
- <TimelineExpandArrowButton
+ hasExpandableContent && nodePathInfo !== null ? (
+ <TimelineSequenceExpandArrow
+ disabled={!previewConnected}
isExpanded={isExpanded}
- onClick={onToggleExpand}
- label="track properties"
- disabled={!previewConnected || nodePathInfo === null}
+ nodePathInfo={nodePathInfo}
+ onToggleExpand={onToggleExpand}
+ sequence={sequence}
/>
) : (
<TimelineExpandArrowSpacer />
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
index c45b9e6773..c61f4d33d9 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
@@ -1,4 +1,7 @@
-import {stringifySequenceSubscriptionKey} from '@remotion/studio-shared';
+import {
+ stringifySequenceExpandedRowKey,
+ stringifySequenceSubscriptionKey,
+} from '@remotion/studio-shared';
import React, {
useCallback,
useContext,
@@ -182,7 +185,7 @@ const findSequenceTrack = ({
readonly tracks: ReturnType<typeof calculateTimeline>;
readonly nodePathInfo: SequenceNodePathInfo;
}) => {
- const key = stringifySequenceSubscriptionKey(
+ const key = stringifySequenceExpandedRowKey(
nodePathInfo.sequenceSubscriptionKey,
);
@@ -192,7 +195,7 @@ const findSequenceTrack = ({
}
return (
- stringifySequenceSubscriptionKey(
+ stringifySequenceExpandedRowKey(
candidate.nodePathInfo.sequenceSubscriptionKey,
) === key && candidate.nodePathInfo.index === nodePathInfo.index
);
@@ -245,13 +248,14 @@ export const getTimelineSequenceDurationDragTargets = ({
: null;
if (
!track ||
+ !track.nodePathInfo ||
!originalSequence ||
!isDurationDraggableSequence(originalSequence)
) {
return null;
}
- const nodePath = nodePathInfo.sequenceSubscriptionKey;
+ const nodePath = track.nodePathInfo.sequenceSubscriptionKey;
if (!canUpdateDurationInFrames({propStatuses, nodePath})) {
return null;
}
@@ -315,13 +319,14 @@ export const getTimelineSequenceFromDragTargets = ({
: null;
if (
!track ||
+ !track.nodePathInfo ||
!originalSequence ||
!isFromDraggableSequence(originalSequence)
) {
return null;
}
- const nodePath = nodePathInfo.sequenceSubscriptionKey;
+ const nodePath = track.nodePathInfo.sequenceSubscriptionKey;
if (!canUpdateFrom({propStatuses, nodePath})) {
return null;
}
diff --git a/packages/studio/src/components/Timeline/find-track-for-node-path-info.ts b/packages/studio/src/components/Timeline/find-track-for-node-path-info.ts
index 0b393d27c9..cbc3bcb553 100644
--- a/packages/studio/src/components/Timeline/find-track-for-node-path-info.ts
+++ b/packages/studio/src/components/Timeline/find-track-for-node-path-info.ts
@@ -1,4 +1,4 @@
-import {stringifySequenceSubscriptionKey} from '@remotion/studio-shared';
+import {stringifySequenceExpandedRowKey} from '@remotion/studio-shared';
import type {OverrideIdToNodePaths, TSequence} from 'remotion';
import {calculateTimeline} from '../../helpers/calculate-timeline';
import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
@@ -16,12 +16,10 @@ export const findTrackForNodePathInfo = ({
return tracks.find(
(candidate) =>
candidate.nodePathInfo !== null &&
- stringifySequenceSubscriptionKey(
+ stringifySequenceExpandedRowKey(
candidate.nodePathInfo.sequenceSubscriptionKey,
) ===
- stringifySequenceSubscriptionKey(
- nodePathInfo.sequenceSubscriptionKey,
- ) &&
+ stringifySequenceExpandedRowKey(nodePathInfo.sequenceSubscriptionKey) &&
candidate.nodePathInfo.index === nodePathInfo.index,
);
};
diff --git a/packages/studio/src/components/Timeline/get-node-keyframes.ts b/packages/studio/src/components/Timeline/get-node-keyframes.ts
index 976b8ddefd..c3d532f450 100644
--- a/packages/studio/src/components/Timeline/get-node-keyframes.ts
+++ b/packages/studio/src/components/Timeline/get-node-keyframes.ts
@@ -114,3 +114,52 @@ export const getNodeKeyframes = ({
hasDragOverride: hasOverride(effectDragOverrides, node.field.key),
});
};
+
+export const getNodeHasKeyframes = ({
+ node,
+ nodePath,
+ propStatuses,
+ getDragOverrides,
+ getEffectDragOverrides,
+}: {
+ node: TimelineTreeNode;
+ nodePath: SequencePropsSubscriptionKey;
+ propStatuses: PropStatuses;
+ getDragOverrides: GetDragOverrides;
+ getEffectDragOverrides: GetEffectDragOverrides;
+}): boolean => {
+ if (node.kind !== 'field' || node.field === null) {
+ return false;
+ }
+
+ if (node.field.kind === 'sequence-field') {
+ const dragOverrides = getDragOverrides(nodePath);
+ if (dragOverrides[node.field.key]?.type === 'keyframed') {
+ return true;
+ }
+
+ return (
+ Internals.getPropStatusesCtx(propStatuses, nodePath)?.[node.field.key]
+ ?.status === 'keyframed'
+ );
+ }
+
+ const effectDragOverrides = getEffectDragOverrides(
+ nodePath,
+ node.field.effectIndex,
+ );
+ if (effectDragOverrides[node.field.key]?.type === 'keyframed') {
+ return true;
+ }
+
+ const effectStatus = Internals.getEffectPropStatusesCtx({
+ propStatuses,
+ nodePath,
+ effectIndex: node.field.effectIndex,
+ });
+
+ return (
+ effectStatus.type === 'can-update-effect' &&
+ effectStatus.props?.[node.field.key]?.status === 'keyframed'
+ );
+};
diff --git a/packages/studio/src/components/Timeline/timeline-expanded-filter.ts b/packages/studio/src/components/Timeline/timeline-expanded-filter.ts
new file mode 100644
index 0000000000..17ee9b2ea5
--- /dev/null
+++ b/packages/studio/src/components/Timeline/timeline-expanded-filter.ts
@@ -0,0 +1,60 @@
+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';
+import type {TimelineSelection} from './TimelineSelection';
+
+export const filterTimelineExpandedTree = ({
+ nodes,
+ shouldShowNode,
+}: {
+ readonly nodes: readonly TimelineTreeNode[];
+ readonly shouldShowNode: (node: TimelineTreeNode) => boolean;
+}): TimelineTreeNode[] => {
+ const out: TimelineTreeNode[] = [];
+
+ for (const node of nodes) {
+ if (node.kind === 'field') {
+ if (shouldShowNode(node)) {
+ out.push(node);
+ }
+
+ continue;
+ }
+
+ const children = filterTimelineExpandedTree({
+ nodes: node.children,
+ shouldShowNode,
+ });
+
+ if (children.length > 0 || shouldShowNode(node)) {
+ out.push({
+ ...node,
+ children,
+ });
+ }
+ }
+
+ return out;
+};
+
+export const getSelectedTimelineExpandedRowKeys = (
+ selectedItems: readonly TimelineSelection[],
+): ReadonlySet<string> => {
+ return new Set(
+ selectedItems.flatMap((item): string[] => {
+ if (item.type === 'guide') {
+ return [];
+ }
+
+ return [timelineNodePathInfoToKey(item.nodePathInfo)];
+ }),
+ );
+};
+
+export const isTimelineExpandedNodeSelected = ({
+ nodePathInfo,
+ selectedRowKeys,
+}: {
+ readonly nodePathInfo: SequenceNodePathInfo;
+ readonly selectedRowKeys: ReadonlySet<string>;
+}): boolean => selectedRowKeys.has(timelineNodePathInfoToKey(nodePathInfo));
diff --git a/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts
index f64d3c2f14..4ecf61fc91 100644
--- a/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts
+++ b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts
@@ -4,13 +4,18 @@ import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sor
import {
buildTimelineTree,
flattenVisibleTreeNodes,
- getExpandedTrackHeight,
getTreeRowHeight,
} from '../../helpers/timeline-layout';
import {timelineNodePathInfoToKey} from '../../helpers/timeline-node-path-key';
import {ExpandedTracksGetterContext} from '../ExpandedTracksProvider';
-import {getNodeKeyframes} from './get-node-keyframes';
+import {getNodeHasKeyframes, getNodeKeyframes} from './get-node-keyframes';
import type {getTimelineKeyframes} from './get-timeline-keyframes';
+import {
+ filterTimelineExpandedTree,
+ getSelectedTimelineExpandedRowKeys,
+ isTimelineExpandedNodeSelected,
+} from './timeline-expanded-filter';
+import {useTimelineSelection} from './TimelineSelection';
const canEditEasingForInterpolationFunction = (
interpolationFunction: string,
@@ -86,6 +91,7 @@ export const useExpandedTrackKeyframeRows = ({
const {getDragOverrides, getEffectDragOverrides} = useContext(
Internals.VisualModeDragOverridesContext,
);
+ const {selectedItems} = useTimelineSelection();
const timelinePosition = Internals.Timeline.useTimelinePosition();
const tree = useMemo(
@@ -106,53 +112,97 @@ export const useExpandedTrackKeyframeRows = ({
],
);
- const flat = useMemo(
- () => flattenVisibleTreeNodes({nodes: tree, getIsExpanded}),
- [tree, getIsExpanded],
+ const selectedRowKeys = useMemo(
+ () => getSelectedTimelineExpandedRowKeys(selectedItems),
+ [selectedItems],
);
- const expandedHeight = useMemo(
+ const filteredTree = useMemo(
() =>
- getExpandedTrackHeight({
- sequence,
- nodePathInfo,
- getIsExpanded,
- propStatuses,
+ filterTimelineExpandedTree({
+ nodes: tree,
+ shouldShowNode: (node) =>
+ isTimelineExpandedNodeSelected({
+ nodePathInfo: node.nodePathInfo,
+ selectedRowKeys,
+ }) ||
+ getNodeHasKeyframes({
+ node,
+ nodePath: nodePathInfo.sequenceSubscriptionKey,
+ propStatuses,
+ getDragOverrides,
+ getEffectDragOverrides,
+ }),
}),
- [propStatuses, getIsExpanded, nodePathInfo, sequence],
+ [
+ getDragOverrides,
+ getEffectDragOverrides,
+ nodePathInfo.sequenceSubscriptionKey,
+ propStatuses,
+ selectedRowKeys,
+ tree,
+ ],
);
- const rows = useMemo(
- (): ExpandedTrackKeyframeRow[] =>
- flat.map(({node}) => ({
- height: getTreeRowHeight(node),
- keyframes: getNodeKeyframes({
- node,
- nodePath: nodePathInfo.sequenceSubscriptionKey,
- propStatuses,
- keyframeDisplayOffset,
- getDragOverrides,
- getEffectDragOverrides,
- timelinePosition,
- }),
- canEditEasing: getNodeCanEditEasing({
- node,
- nodePath: nodePathInfo.sequenceSubscriptionKey,
- propStatuses,
- }),
- rowKey: timelineNodePathInfoToKey(node.nodePathInfo),
- nodePathInfo: node.nodePathInfo,
- })),
+ const flat = useMemo(
+ () => flattenVisibleTreeNodes({nodes: filteredTree, getIsExpanded}),
+ [filteredTree, getIsExpanded],
+ );
+
+ const expandedHeight = useMemo(() => {
+ const totalRowsHeight = flat.reduce(
+ (sum, {node}) => sum + getTreeRowHeight(node),
+ 0,
+ );
+ const separators = Math.max(0, flat.length - 1);
+ return totalRowsHeight + separators;
+ }, [flat]);
+
+ const nodeKeyframes = useMemo(
+ () =>
+ new Map(
+ flat.map(({node}) => [
+ timelineNodePathInfoToKey(node.nodePathInfo),
+ getNodeKeyframes({
+ node,
+ nodePath: nodePathInfo.sequenceSubscriptionKey,
+ propStatuses,
+ keyframeDisplayOffset,
+ getDragOverrides,
+ getEffectDragOverrides,
+ timelinePosition,
+ }),
+ ]),
+ ),
[
- propStatuses,
flat,
getDragOverrides,
getEffectDragOverrides,
keyframeDisplayOffset,
nodePathInfo.sequenceSubscriptionKey,
+ propStatuses,
timelinePosition,
],
);
+ const rows = useMemo(
+ (): ExpandedTrackKeyframeRow[] =>
+ flat.map(({node}) => {
+ const rowKey = timelineNodePathInfoToKey(node.nodePathInfo);
+ return {
+ height: getTreeRowHeight(node),
+ keyframes: nodeKeyframes.get(rowKey) ?? [],
+ canEditEasing: getNodeCanEditEasing({
+ node,
+ nodePath: nodePathInfo.sequenceSubscriptionKey,
+ propStatuses,
+ }),
+ rowKey,
+ nodePathInfo: node.nodePathInfo,
+ };
+ }),
+ [propStatuses, flat, nodePathInfo.sequenceSubscriptionKey, nodeKeyframes],
+ );
+
return {rows, expandedHeight};
};
diff --git a/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts b/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts
index f387b32f68..09092a1037 100644
--- a/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts
+++ b/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts
@@ -6,6 +6,13 @@ import {
ExpandedTracksGetterContext,
ExpandedTracksSetterContext,
} from '../ExpandedTracksProvider';
+import {getNodeHasKeyframes} from './get-node-keyframes';
+import {
+ filterTimelineExpandedTree,
+ getSelectedTimelineExpandedRowKeys,
+ isTimelineExpandedNodeSelected,
+} from './timeline-expanded-filter';
+import {useTimelineSelection} from './TimelineSelection';
export const useTimelineExpandedTree = ({
sequence,
@@ -22,6 +29,7 @@ export const useTimelineExpandedTree = ({
const {getDragOverrides, getEffectDragOverrides} = useContext(
Internals.VisualModeDragOverridesContext,
);
+ const {selectedItems} = useTimelineSelection();
const tree = useMemo(
() =>
@@ -40,8 +48,39 @@ export const useTimelineExpandedTree = ({
visualModePropStatuses,
],
);
+ const selectedRowKeys = useMemo(
+ () => getSelectedTimelineExpandedRowKeys(selectedItems),
+ [selectedItems],
+ );
+ const filteredTree = useMemo(
+ () =>
+ filterTimelineExpandedTree({
+ nodes: tree,
+ shouldShowNode: (node) =>
+ isTimelineExpandedNodeSelected({
+ nodePathInfo: node.nodePathInfo,
+ selectedRowKeys,
+ }) ||
+ getNodeHasKeyframes({
+ node,
+ nodePath: nodePathInfo.sequenceSubscriptionKey,
+ propStatuses: visualModePropStatuses,
+ getDragOverrides,
+ getEffectDragOverrides,
+ }),
+ }),
+ [
+ getDragOverrides,
+ getEffectDragOverrides,
+ nodePathInfo.sequenceSubscriptionKey,
+ selectedRowKeys,
+ tree,
+ visualModePropStatuses,
+ ],
+ );
return {
+ filteredTree,
getIsExpanded,
propStatuses: visualModePropStatuses,
toggleTrack,
diff --git a/packages/studio/src/components/Timeline/use-timeline-height.ts b/packages/studio/src/components/Timeline/use-timeline-height.ts
index f7d41a04a4..bfc1b36a5f 100644
--- a/packages/studio/src/components/Timeline/use-timeline-height.ts
+++ b/packages/studio/src/components/Timeline/use-timeline-height.ts
@@ -3,12 +3,21 @@ import {Internals} from 'remotion';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
import type {TrackWithHash} from '../../helpers/get-timeline-sequence-sort-key';
import {
- getExpandedTrackHeight,
+ buildTimelineTree,
+ flattenVisibleTreeNodes,
+ getTreeRowHeight,
getTimelineLayerHeight,
TIMELINE_ITEM_BORDER_BOTTOM,
} from '../../helpers/timeline-layout';
import {ExpandedTracksGetterContext} from '../ExpandedTracksProvider';
+import {getNodeHasKeyframes} from './get-node-keyframes';
import {MAX_TIMELINE_TRACKS_NOTICE_HEIGHT} from './MaxTimelineTracks';
+import {
+ filterTimelineExpandedTree,
+ getSelectedTimelineExpandedRowKeys,
+ isTimelineExpandedNodeSelected,
+} from './timeline-expanded-filter';
+import {useTimelineSelection} from './TimelineSelection';
import {TIMELINE_TIME_INDICATOR_HEIGHT} from './TimelineTimeIndicators';
export const useTimelineHeight = ({
@@ -21,8 +30,16 @@ export const useTimelineHeight = ({
const {getIsExpanded} = useContext(ExpandedTracksGetterContext);
const {previewServerState} = useContext(StudioServerConnectionCtx);
const {propStatuses} = useContext(Internals.VisualModePropStatusesContext);
+ const {getDragOverrides, getEffectDragOverrides} = useContext(
+ Internals.VisualModeDragOverridesContext,
+ );
+ const {selectedItems} = useTimelineSelection();
const previewServerConnected = previewServerState.type === 'connected';
+ const selectedRowKeys = useMemo(
+ () => getSelectedTimelineExpandedRowKeys(selectedItems),
+ [selectedItems],
+ );
return useMemo(() => {
const tracksHeight = shown.reduce((acc, track) => {
@@ -33,15 +50,50 @@ export const useTimelineHeight = ({
const layerHeight =
getTimelineLayerHeight(track.sequence.type) +
TIMELINE_ITEM_BORDER_BOTTOM;
- const expandedHeight =
- isExpanded && track.nodePathInfo
- ? getExpandedTrackHeight({
- sequence: track.sequence,
- nodePathInfo: track.nodePathInfo,
- getIsExpanded,
+ const expandedHeight = (() => {
+ if (!isExpanded || track.nodePathInfo === null) {
+ return 0;
+ }
+
+ const {nodePathInfo} = track;
+ const tree = buildTimelineTree({
+ sequence: track.sequence,
+ nodePathInfo,
+ getDragOverrides,
+ getEffectDragOverrides,
+ propStatuses,
+ });
+ const filteredTree = filterTimelineExpandedTree({
+ nodes: tree,
+ shouldShowNode: (node) =>
+ isTimelineExpandedNodeSelected({
+ nodePathInfo: node.nodePathInfo,
+ selectedRowKeys,
+ }) ||
+ getNodeHasKeyframes({
+ node,
+ nodePath: nodePathInfo.sequenceSubscriptionKey,
propStatuses,
- }) + TIMELINE_ITEM_BORDER_BOTTOM
- : 0;
+ getDragOverrides,
+ getEffectDragOverrides,
+ }),
+ });
+ const flat = flattenVisibleTreeNodes({
+ nodes: filteredTree,
+ getIsExpanded,
+ });
+
+ if (flat.length === 0) {
+ return 0;
+ }
+
+ const totalRowsHeight = flat.reduce(
+ (sum, {node}) => sum + getTreeRowHeight(node),
+ 0,
+ );
+ const separators = Math.max(0, flat.length - 1);
+ return totalRowsHeight + separators + TIMELINE_ITEM_BORDER_BOTTOM;
+ })();
return acc + layerHeight + expandedHeight;
}, 0);
@@ -51,5 +103,14 @@ export const useTimelineHeight = ({
(hasBeenCut ? MAX_TIMELINE_TRACKS_NOTICE_HEIGHT : 0) +
TIMELINE_TIME_INDICATOR_HEIGHT
);
- }, [shown, hasBeenCut, previewServerConnected, getIsExpanded, propStatuses]);
+ }, [
+ shown,
+ hasBeenCut,
+ previewServerConnected,
+ getIsExpanded,
+ propStatuses,
+ getDragOverrides,
+ getEffectDragOverrides,
+ selectedRowKeys,
+ ]);
};
diff --git a/packages/studio/src/helpers/migrate-expanded-tracks-for-subscription-key.ts b/packages/studio/src/helpers/migrate-expanded-tracks-for-subscription-key.ts
index e8745d7271..50530167e0 100644
--- a/packages/studio/src/helpers/migrate-expanded-tracks-for-subscription-key.ts
+++ b/packages/studio/src/helpers/migrate-expanded-tracks-for-subscription-key.ts
@@ -18,13 +18,13 @@ export const migrateExpandedTracksForSubscriptionKey = (
const next: BooleanMap = {...prev};
for (const [key, value] of Object.entries(prev)) {
- if (!value || !key.startsWith(oldPrefix + '.')) {
+ if (value !== false || !key.startsWith(oldPrefix + '.')) {
continue;
}
const migratedKey = newPrefix + key.slice(oldPrefix.length);
- if (!next[migratedKey]) {
- next[migratedKey] = true;
+ if (next[migratedKey] === undefined) {
+ next[migratedKey] = false;
}
delete next[key];
diff --git a/packages/studio/src/test/migrate-expanded-tracks-for-subscription-key.test.ts b/packages/studio/src/test/migrate-expanded-tracks-for-subscription-key.test.ts
index 6ef064d0db..7d70c66b97 100644
--- a/packages/studio/src/test/migrate-expanded-tracks-for-subscription-key.test.ts
+++ b/packages/studio/src/test/migrate-expanded-tracks-for-subscription-key.test.ts
@@ -21,26 +21,39 @@ const expandedKey = (
index,
].join('.');
-test('migrates expanded keys when subscription node path changes', () => {
+test('migrates collapsed keys when subscription node path changes', () => {
const oldKey = makeKey(['body', 0, 'children', 1]);
const newKey = makeKey(['body', 0, 'children', 2]);
const unrelatedKey = makeKey(['body', 0, 'children', 3]);
const prev = {
- [expandedKey(oldKey, [], 0)]: true,
- [expandedKey(oldKey, ['controls', 'from'], 0)]: true,
- [expandedKey(unrelatedKey, [], 0)]: true,
+ [expandedKey(oldKey, [], 0)]: false,
+ [expandedKey(oldKey, ['controls', 'from'], 0)]: false,
+ [expandedKey(unrelatedKey, [], 0)]: false,
};
const next = migrateExpandedTracksForSubscriptionKey(prev, oldKey, newKey);
expect(next).toEqual({
- [expandedKey(newKey, [], 0)]: true,
- [expandedKey(newKey, ['controls', 'from'], 0)]: true,
- [expandedKey(unrelatedKey, [], 0)]: true,
+ [expandedKey(newKey, [], 0)]: false,
+ [expandedKey(newKey, ['controls', 'from'], 0)]: false,
+ [expandedKey(unrelatedKey, [], 0)]: false,
});
});
+test('ignores expanded keys when subscription node path changes', () => {
+ const oldKey = makeKey(['body', 0, 'children', 1]);
+ const newKey = makeKey(['body', 0, 'children', 2]);
+
+ const prev = {
+ [expandedKey(oldKey, [], 0)]: true,
+ };
+
+ expect(migrateExpandedTracksForSubscriptionKey(prev, oldKey, newKey)).toBe(
+ null,
+ );
+});
+
test('returns null when subscription key is unchanged', () => {
const key = makeKey(['body', 0]);
const prev = {
diff --git a/packages/studio/src/test/timeline-keyframes.test.ts b/packages/studio/src/test/timeline-keyframes.test.ts
index ad401ee5df..f29d00d52a 100644
--- a/packages/studio/src/test/timeline-keyframes.test.ts
+++ b/packages/studio/src/test/timeline-keyframes.test.ts
@@ -5,6 +5,7 @@ import type {
TSequence,
} from 'remotion';
import {Internals, type PropStatuses} from 'remotion';
+import {findTrackForNodePathInfo} from '../components/Timeline/find-track-for-node-path-info';
import {getBoundedKeyframeDragDelta} from '../components/Timeline/get-bounded-keyframe-drag-delta';
import {getNodeKeyframes} from '../components/Timeline/get-node-keyframes';
import {getTimelineEasingSegments} from '../components/Timeline/get-timeline-easing-segments';
@@ -22,6 +23,14 @@ const makeNodePath = (id: string): SequencePropsSubscriptionKey => ({
effectKeys: [],
});
+const makeNodePathWithEffectKeys = (
+ id: string,
+ effectKeys: string[][],
+): SequencePropsSubscriptionKey => ({
+ ...makeNodePath(id),
+ effectKeys,
+});
+
const makeControls = (
overrideId: string,
): NonNullable<TSequence['controls']> => ({
@@ -232,6 +241,38 @@ test('keyframe display offsets follow the parent sequence context', () => {
]);
});
+test('track lookup survives effect key changes', () => {
+ const sequences = [
+ makeSequence({
+ id: 'sequence',
+ from: 0,
+ overrideId: 'sequence',
+ nonce: 0,
+ }),
+ ];
+ const currentNodePath = makeNodePathWithEffectKeys('sequence', [
+ ['blur'],
+ ['noise'],
+ ]);
+ const staleNodePath = makeNodePathWithEffectKeys('sequence', [['blur']]);
+
+ const track = findTrackForNodePathInfo({
+ sequences,
+ overrideIdsToNodePaths: {
+ sequence: currentNodePath,
+ },
+ nodePathInfo: {
+ sequenceSubscriptionKey: staleNodePath,
+ auxiliaryKeys: [],
+ index: 0,
+ numberOfSequencesWithThisNodePath: 1,
+ supportsEffects: true,
+ },
+ });
+
+ expect(track?.nodePathInfo?.sequenceSubscriptionKey).toBe(currentNodePath);
+});
+
test('timeline easing segments connect adjacent display keyframes', () => {
const status: CanUpdateSequencePropStatusKeyframed = {
...makeKeyframedStatus(),