Skip to content

🎥 Make videos programmatically with React

Show selected item type in inspector title

JonnyBurgerfbfe990f3393
diff --git a/packages/studio/src/components/InspectorPanel/SelectedInspector.tsx b/packages/studio/src/components/InspectorPanel/SelectedInspector.tsx
index 02ee46ca10..60acdb5e2c 100644
--- a/packages/studio/src/components/InspectorPanel/SelectedInspector.tsx
+++ b/packages/studio/src/components/InspectorPanel/SelectedInspector.tsx
@@ -1,9 +1,5 @@
-import React, {useLayoutEffect, useRef, useState} from 'react';
-import {startSlideViewTransition} from '../../helpers/slide-view-transition';
-import {
- getTimelineSequenceSelectionKey,
- type TimelineSelection,
-} from '../Timeline/TimelineSelection';
+import React from 'react';
+import type {TimelineSelection} from '../Timeline/TimelineSelection';
import {InspectorMessage} from './common';
import {EasingInspector} from './EasingInspector';
import {GuideInspector} from './GuideInspector';
@@ -44,57 +40,10 @@ export const SelectedInspector: React.FC<{
readonly selection: TimelineSelection;
readonly readOnlyStudio: boolean;
}> = ({selection, readOnlyStudio}) => {
- const [displayedSelection, setDisplayedSelection] = useState(selection);
- const displayedSelectionRef = useRef(selection);
- const panelRef = useRef<HTMLDivElement>(null);
-
- useLayoutEffect(() => {
- const previous = displayedSelectionRef.current;
- if (previous === selection) {
- return;
- }
-
- const forward =
- isSequenceSectionSelection(previous) &&
- (selection.type === 'keyframe' || selection.type === 'easing');
- const backward =
- (previous.type === 'keyframe' || previous.type === 'easing') &&
- isSequenceSectionSelection(selection);
- const panel = panelRef.current;
- if (
- (!forward && !backward) ||
- getTimelineSequenceSelectionKey(previous.nodePathInfo) !==
- getTimelineSequenceSelectionKey(selection.nodePathInfo) ||
- panel === null
- ) {
- displayedSelectionRef.current = selection;
- setDisplayedSelection(selection);
- return;
- }
-
- // Defer only the inspector DOM swap; timeline selection stays synchronous.
- const update = () => {
- displayedSelectionRef.current = selection;
- setDisplayedSelection(selection);
- };
-
- const cancel = startSlideViewTransition({
- panels: [{element: panel, name: 'remotion-inspector', clipY: null}],
- direction: forward ? 'forward' : 'backward',
- update,
- });
- if (cancel === null) {
- update();
- return;
- }
-
- return cancel;
- }, [selection]);
-
return (
- <div ref={panelRef} style={container}>
+ <div style={container}>
<SelectedInspectorContent
- selection={displayedSelection}
+ selection={selection}
readOnlyStudio={readOnlyStudio}
/>
</div>
diff --git a/packages/studio/src/components/OptionsPanel.tsx b/packages/studio/src/components/OptionsPanel.tsx
index b7c18ffb16..90d577dfb8 100644
--- a/packages/studio/src/components/OptionsPanel.tsx
+++ b/packages/studio/src/components/OptionsPanel.tsx
@@ -12,6 +12,10 @@ import {useMobileLayout} from '../helpers/mobile-layout';
import {resolvedStackToSymbolicated} from '../helpers/resolved-stack-to-symbolicated';
import {useZodIfPossible, useZodTypesIfPossible} from './get-zod-if-possible';
import {InspectorPanel} from './InspectorPanel';
+import {
+ getSameSequenceInspectorSelection,
+ isSequenceSectionSelection,
+} from './InspectorPanel/inspector-selection';
import {showNotification} from './Notifications/NotificationCenter';
import {optionsSidebarTabs} from './options-sidebar-tabs';
import {deepEqual} from './RenderModal/SchemaEditor/deep-equal';
@@ -23,6 +27,7 @@ import {RenderQueue} from './RenderQueue';
import {callUpdateDefaultPropsApi} from './RenderQueue/actions';
import {RendersTab} from './RendersTab';
import {Tab, Tabs} from './Tabs';
+import {useTimelineSelection} from './Timeline/TimelineSelection';
import {
getCachedResolvedStack,
useResolvedStack,
@@ -112,6 +117,44 @@ export const OptionsPanel: React.FC<{
return null;
}, [canvasContent, compositions]);
+ const {selectedItems} = useTimelineSelection();
+ const inspectorTitle = useMemo(() => {
+ if (selectedItems.length === 0) {
+ if (canvasContent?.type === 'asset') {
+ return 'Asset';
+ }
+
+ return composition === null ? 'Selection' : 'Composition';
+ }
+
+ const selection =
+ selectedItems.length === 1
+ ? selectedItems[0]
+ : getSameSequenceInspectorSelection(selectedItems);
+ if (selection === null) {
+ return selectedItems.every((item) => item.type === 'sequence')
+ ? 'Sequences'
+ : 'Selection';
+ }
+
+ if (isSequenceSectionSelection(selection)) {
+ return 'Sequence';
+ }
+
+ switch (selection.type) {
+ case 'keyframe':
+ return 'Keyframe';
+ case 'easing':
+ return 'Easing';
+ case 'guide':
+ return 'Guide';
+ default:
+ throw new Error(
+ `Unexpected inspector selection: ${selection satisfies never}`,
+ );
+ }
+ }, [canvasContent, composition, selectedItems]);
+
// Re-renders once the stack is resolved. Read from the cache so the location
// always belongs to the current composition, not the previously selected one.
useResolvedStack(composition?.stack ?? null);
@@ -264,7 +307,7 @@ export const OptionsPanel: React.FC<{
onClick={onInspectorSelected}
style={{justifyContent: 'space-between'}}
>
- Inspector
+ {inspectorTitle}
{hasLocalModifications ? (
<SchemaResetButton onClick={resetToOriginal} />
) : null}