Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Fix inspector jumps when selecting effects in inspector

Jonny Burger4c5db9540d53
diff --git a/packages/example/e2e/studio.test.mts b/packages/example/e2e/studio.test.mts
index 8d999203ce..0255cf88e7 100644
--- a/packages/example/e2e/studio.test.mts
+++ b/packages/example/e2e/studio.test.mts
@@ -734,7 +734,21 @@ test.describe('visual mode', () => {
.locator('.__remotion-vertical-scrollbar')
.filter({has: addEffectButton});
const inspectorWave = inspector.getByText('wave()', {exact: true});
+ await inspectorWave.evaluate((element) => {
+ element.scrollIntoView({block: 'center'});
+ });
+ await inspector.evaluate((element) => {
+ element.scrollTop += 60;
+ });
+ await expect(inspectorWave).toBeInViewport();
+ const inspectorScrollBeforeClick = await inspector.evaluate(
+ (element) => element.scrollTop,
+ );
+ expect(inspectorScrollBeforeClick).toBeGreaterThan(0);
await inspectorWave.click();
+ await expect
+ .poll(() => inspector.evaluate((element) => element.scrollTop))
+ .toBe(inspectorScrollBeforeClick);
const timelineWave = page
.getByText('wave()', {exact: true})
.filter({visible: true})
diff --git a/packages/studio/src/components/InspectorSequenceSection.tsx b/packages/studio/src/components/InspectorSequenceSection.tsx
index 2cd1451df8..24d7b8719b 100644
--- a/packages/studio/src/components/InspectorSequenceSection.tsx
+++ b/packages/studio/src/components/InspectorSequenceSection.tsx
@@ -331,7 +331,7 @@ export const InspectorSequenceSection: React.FC<{
includeTextContent: true,
includeSourceControls: true,
});
- const {selectedItems} = useTimelineSelection();
+ const {inspectorRevealRequest, selectedItems} = useTimelineSelection();
const selectedEffect =
selectedItems.length === 1 &&
(selectedItems[0].type === 'sequence-effect' ||
@@ -340,8 +340,18 @@ export const InspectorSequenceSection: React.FC<{
: null;
const selectedEffectKey =
selectedEffect === null ? null : getTimelineSelectionKey(selectedEffect);
+ const inspectorRevealItem = inspectorRevealRequest?.item;
+ const inspectorRevealItemKey =
+ inspectorRevealItem?.type === 'sequence-effect' ||
+ inspectorRevealItem?.type === 'sequence-effect-prop'
+ ? getTimelineSelectionKey(inspectorRevealItem)
+ : null;
+ const inspectorRevealToken =
+ inspectorRevealItemKey === selectedEffectKey
+ ? (inspectorRevealRequest?.token ?? null)
+ : null;
const selectedEffectRowRef = useRef<HTMLDivElement>(null);
- const scrolledEffectKey = useRef<string | null>(null);
+ const scrolledInspectorRevealToken = useRef<number | null>(null);
const [collapsedKeys, setCollapsedKeys] = useState<ReadonlySet<string>>(
loadInspectorCollapsedKeys,
);
@@ -473,7 +483,8 @@ export const InspectorSequenceSection: React.FC<{
useEffect(() => {
if (
selectedEffectKey === null ||
- scrolledEffectKey.current === selectedEffectKey
+ inspectorRevealToken === null ||
+ scrolledInspectorRevealToken.current === inspectorRevealToken
) {
return;
}
@@ -515,24 +526,23 @@ export const InspectorSequenceSection: React.FC<{
persistInspectorCollapsedKeys(next);
return next;
});
- }, [selectedEffectKey, tree]);
+ }, [inspectorRevealToken, selectedEffectKey, tree]);
useEffect(() => {
- if (selectedEffectKey === null) {
- scrolledEffectKey.current = null;
+ if (inspectorRevealToken === null) {
return;
}
if (
- scrolledEffectKey.current === selectedEffectKey ||
+ scrolledInspectorRevealToken.current === inspectorRevealToken ||
selectedEffectRowRef.current === null
) {
return;
}
selectedEffectRowRef.current.scrollIntoView({block: 'center'});
- scrolledEffectKey.current = selectedEffectKey;
- }, [effectRows, selectedEffectKey]);
+ scrolledInspectorRevealToken.current = inspectorRevealToken;
+ }, [effectRows, inspectorRevealToken]);
const effectSelectableItems = useMemo(
() => getInspectorSelectableItems(effectRows),
diff --git a/packages/studio/src/components/Timeline/TimelineEffectItem.tsx b/packages/studio/src/components/Timeline/TimelineEffectItem.tsx
index 7b4659b2b8..af2c390cca 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectItem.tsx
@@ -126,6 +126,7 @@ export const TimelineEffectItem: React.FC<{
readonly validatedLocation: CodePosition;
readonly rowDepth: number;
readonly labelNextToToggle: boolean;
+ readonly revealInInspector: boolean;
readonly getIsExpanded: GetIsExpanded;
readonly toggleTrack: (nodePathInfo: SequenceNodePathInfo) => void;
}> = ({
@@ -138,6 +139,7 @@ export const TimelineEffectItem: React.FC<{
validatedLocation,
rowDepth,
labelNextToToggle,
+ revealInInspector,
getIsExpanded,
toggleTrack,
}) => {
@@ -146,7 +148,7 @@ export const TimelineEffectItem: React.FC<{
const canMutateEffects = canUseEffectOperations();
const {propStatuses} = useContext(Internals.VisualModePropStatusesContext);
const {setPropStatuses} = useContext(Internals.VisualModeSettersContext);
- const selection = useTimelineRowSelection(nodePathInfo);
+ const selection = useTimelineRowSelection(nodePathInfo, revealInInspector);
const containsSelection = useTimelineRowContainsSelection(nodePathInfo);
const [dropIndicator, setDropIndicator] = useState<'before' | 'after' | null>(
null,
diff --git a/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx b/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
index 282acedfac..48606046e7 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
@@ -418,6 +418,7 @@ export const TimelineEffectPropItem: React.FC<{
readonly nodePathInfo: SequenceNodePathInfo;
readonly keyframeDisplayOffset: number;
readonly keyframeControlsMode: TimelineKeyframeControlsMode;
+ readonly revealInInspector: boolean;
readonly runtimeValueStore: RuntimeValueStore | null;
}> = ({
field,
@@ -427,6 +428,7 @@ export const TimelineEffectPropItem: React.FC<{
nodePathInfo,
keyframeDisplayOffset,
keyframeControlsMode,
+ revealInInspector,
runtimeValueStore,
}) => {
const {previewServerState} = useContext(StudioServerConnectionCtx);
@@ -438,7 +440,7 @@ export const TimelineEffectPropItem: React.FC<{
const {getEffectDragOverrides} = useContext(
Internals.VisualModeDragOverridesContext,
);
- const selection = useTimelineRowSelection(nodePathInfo);
+ const selection = useTimelineRowSelection(nodePathInfo, revealInInspector);
const style = useMemo((): React.CSSProperties => {
return field.typeName === 'text-content'
? fieldRowBase
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
index a11a5de0e6..f251659ea9 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
@@ -93,6 +93,7 @@ const TimelineExpandedRowInner: React.FC<TimelineExpandedRowProps> = ({
validatedLocation={validatedLocation}
rowDepth={rowDepth}
labelNextToToggle={isInspector}
+ revealInInspector={!isInspector}
getIsExpanded={getIsExpanded}
toggleTrack={toggleTrack}
/>
@@ -139,6 +140,7 @@ const TimelineExpandedRowInner: React.FC<TimelineExpandedRowProps> = ({
nodePathInfo={node.nodePathInfo}
keyframeDisplayOffset={keyframeDisplayOffset}
keyframeControlsMode={keyframeControlsMode}
+ revealInInspector={!isInspector}
runtimeValueStore={node.runtimeValueStore}
/>
);
diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsx
index 0a44b4d4ca..609236d951 100644
--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx
@@ -432,6 +432,7 @@ export const extendTimelineMarqueeSelection = ({
type TimelineSelectionContextValue = {
readonly canSelect: boolean;
+ readonly inspectorRevealRequest: TimelineSelectionRevealRequest | null;
readonly revealRequest: TimelineSelectionRevealRequest | null;
readonly selectedItems: readonly TimelineSelection[];
readonly isSelected: (item: TimelineSelection) => boolean;
@@ -465,6 +466,7 @@ type TimelineSelectionContextValue = {
const defaultTimelineSelectionContextValue: TimelineSelectionContextValue = {
canSelect: false,
+ inspectorRevealRequest: null,
revealRequest: null,
selectedItems: [],
isSelected: () => false,
@@ -509,6 +511,7 @@ const CurrentTimelineSelectionContext =
type TimelineSelectionOptions = {
readonly reveal?: boolean;
+ readonly revealInInspector?: boolean;
};
type TimelineSelectionRevealRequest = {
@@ -965,10 +968,14 @@ export const TimelineSelectionProvider: React.FC<{
const marqueeRegistrationCounter = useRef(0);
const [revealRequest, setRevealRequest] =
useState<TimelineSelectionRevealRequest | null>(null);
+ const [inspectorRevealRequest, setInspectorRevealRequest] =
+ useState<TimelineSelectionRevealRequest | null>(null);
+ const inspectorRevealTokenCounter = useRef(0);
useEffect(() => {
if (!canSelect) {
selectionScope.current = null;
+ setInspectorRevealRequest(null);
setRevealRequest(null);
selectionController.clear();
}
@@ -995,6 +1002,16 @@ export const TimelineSelectionProvider: React.FC<{
token: (previousRequest?.token ?? 0) + 1,
}));
}, []);
+ const requestRevealSelectionItemInInspector = useCallback(
+ (item: TimelineSelection) => {
+ inspectorRevealTokenCounter.current += 1;
+ setInspectorRevealRequest({
+ item,
+ token: inspectorRevealTokenCounter.current,
+ });
+ },
+ [],
+ );
const expandParentsForSelectionItems = useCallback(
(items: readonly TimelineSelection[]) => {
@@ -1061,6 +1078,12 @@ export const TimelineSelectionProvider: React.FC<{
requestRevealSelectionItem(item);
}
+ if (options.revealInInspector) {
+ requestRevealSelectionItemInInspector(item);
+ } else {
+ setInspectorRevealRequest(null);
+ }
+
if (selectionScope.current !== timelineSelectionScope) {
selectionController.clear();
}
@@ -1071,6 +1094,7 @@ export const TimelineSelectionProvider: React.FC<{
[
canSelectItem,
expandParentsForSelectionItem,
+ requestRevealSelectionItemInInspector,
requestRevealSelectionItem,
selectionController,
timelineSelectionScope,
@@ -1096,11 +1120,18 @@ export const TimelineSelectionProvider: React.FC<{
requestRevealSelectionItem(items[0]);
}
+ if (options.revealInInspector && items.length === 1) {
+ requestRevealSelectionItemInInspector(items[0]);
+ } else {
+ setInspectorRevealRequest(null);
+ }
+
selectionController.setSelectedItems(items);
},
[
canSelectItem,
expandParentsForSelectionItems,
+ requestRevealSelectionItemInInspector,
requestRevealSelectionItem,
selectionController,
timelineSelectionScope,
@@ -1165,6 +1196,7 @@ export const TimelineSelectionProvider: React.FC<{
const clearSelection = useCallback(() => {
selectionScope.current = null;
+ setInspectorRevealRequest(null);
selectionController.clear();
}, [selectionController]);
@@ -1257,6 +1289,7 @@ export const TimelineSelectionProvider: React.FC<{
const value = useMemo(
(): TimelineSelectionContextValue => ({
canSelect,
+ inspectorRevealRequest,
revealRequest,
selectedItems: availableSelectedItems,
isSelected,
@@ -1270,6 +1303,7 @@ export const TimelineSelectionProvider: React.FC<{
}),
[
canSelect,
+ inspectorRevealRequest,
revealRequest,
availableSelectedItems,
isSelected,
@@ -1541,6 +1575,7 @@ export const useTimelineMarqueeSelectableItem = (
export const useTimelineRowSelection = (
nodePathInfo: SequenceNodePathInfo | null,
+ revealInInspector = false,
) => {
const {canSelect, isSelected, selectItem} = useTimelineSelection();
const selectableTimelineItemsRef = useContext(SelectableTimelineItemsContext);
@@ -1562,9 +1597,10 @@ export const useTimelineRowSelection = (
selectionItem,
interaction,
selectableTimelineItemsRef.current,
+ {revealInInspector},
);
},
- [selectItem, selectableTimelineItemsRef, selectionItem],
+ [revealInInspector, selectItem, selectableTimelineItemsRef, selectionItem],
);
return {