Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Open canvas elements in editor on double-click (#9132)

Jonny Burger12e668538e07
diff --git a/packages/studio/src/components/SelectedOutlineElement.tsx b/packages/studio/src/components/SelectedOutlineElement.tsx
index ad04d1f9d3..8fb28df7cd 100644
--- a/packages/studio/src/components/SelectedOutlineElement.tsx
+++ b/packages/studio/src/components/SelectedOutlineElement.tsx
@@ -1,5 +1,4 @@
import React, {useContext, useMemo, useRef, useState} from 'react';
-import {flushSync} from 'react-dom';
import type {ResolvedStackLocation} from 'remotion';
import {Internals} from 'remotion';
import {NoReactInternals} from 'remotion/no-react';
@@ -29,7 +28,6 @@ import {
} from './ForceSpecificCursor';
import type {ComboboxValue} from './NewComposition/ComboBox';
import {showNotification} from './Notifications/NotificationCenter';
-import {optionsSidebarTabs} from './options-sidebar-tabs';
import {
applySelectedOutlineDragAxisLock,
applySelectedOutlineTransformOriginAxisLock,
@@ -61,6 +59,7 @@ import type {OutlinePoint, SelectedOutline} from './selected-outline-geometry';
import {
dot,
getAngleDegrees,
+ getOutlineDoubleClickAction,
getOutlineSelectionInteraction,
getRotationCursor,
getSelectedOutlineRotationCornerInfo,
@@ -96,10 +95,7 @@ import {
} from './Timeline/call-add-keyframe';
import {disableSequenceInteractivity} from './Timeline/disable-sequence-interactivity';
import {duplicateSequencesFromSource} from './Timeline/duplicate-selected-timeline-item';
-import {
- commitPendingInspectorFields,
- requestFocusInspectorField,
-} from './Timeline/focus-inspector-field';
+import {commitPendingInspectorFields} from './Timeline/focus-inspector-field';
import {getSequenceContextMenuItems} from './Timeline/get-sequence-context-menu-items';
import {saveSequenceProps} from './Timeline/save-sequence-prop';
import {getTimelineAssetLinkInfo} from './Timeline/timeline-asset-link';
@@ -497,7 +493,10 @@ const SelectedOutlinePolygon: React.FC<{
item: TimelineSelection,
interaction: TimelineSelectionInteraction,
) => void;
- readonly onTextEditStart: (target: SelectedOutlineTarget) => void;
+ readonly onDoubleClickTarget: (
+ target: SelectedOutlineTarget,
+ button: number,
+ ) => boolean;
readonly scale: number;
readonly snapTargets: readonly SelectedOutlineSnapTarget[];
readonly target: SelectedOutlineTarget | undefined;
@@ -513,7 +512,7 @@ const SelectedOutlinePolygon: React.FC<{
onHoverChange,
onSnapPointsChange,
onSelect,
- onTextEditStart,
+ onDoubleClickTarget,
scale,
snapTargets,
target,
@@ -790,11 +789,14 @@ const SelectedOutlinePolygon: React.FC<{
return;
}
+ if (!onDoubleClickTarget(target, event.button)) {
+ return;
+ }
+
event.preventDefault();
event.stopPropagation();
- onTextEditStart(target);
},
- [onTextEditStart, target],
+ [onDoubleClickTarget, target],
);
const onEffectDragOver = React.useCallback(
@@ -1541,38 +1543,59 @@ export const SelectedOutlineElement: React.FC<{
const selectAsset = useSelectAsset();
const {setSelectedModal} = useContext(ModalsContext);
- const onTextEditStart = React.useCallback(
- (editTarget: SelectedOutlineTarget) => {
- const {textEdit} = editTarget;
- if (textEdit === null) {
- return;
+ const resolveOriginalLocation = React.useCallback(
+ async (resolveTarget: SelectedOutlineTarget) => {
+ const stack = resolveTarget.sequence.getStack();
+ if (!stack) {
+ return null;
}
- if (
- textEdit.propStatus.status !== 'static' ||
- typeof textEdit.propStatus.codeValue !== 'string'
- ) {
- showNotification(
- 'This text is computed and cannot be edited visually',
- 3000,
+ let originalLocation: ResolvedStackLocation | null = null;
+ try {
+ originalLocation = await getOriginalLocationFromStack(
+ stack,
+ 'sequence',
);
- return;
+ } catch (err) {
+ showNotification((err as Error).message, 2000);
}
- flushSync(() => {
- if (!editTarget.selected) {
- onSelect(editTarget.selection, {shiftKey: false, toggleKey: false});
- }
+ updateResolvedStackTrace(stack, originalLocation);
+ return originalLocation;
+ },
+ [updateResolvedStackTrace],
+ );
- optionsSidebarTabs.current?.selectInspectorPanel();
+ const onDoubleClickTarget = React.useCallback(
+ (doubleClickTarget: SelectedOutlineTarget, button: number) => {
+ const action = getOutlineDoubleClickAction({
+ button,
+ canOpenInEditor:
+ previewServerState.type === 'connected' &&
+ Boolean(window.remotion_editorName),
});
- requestFocusInspectorField({
- fieldKey: 'children',
- nodePath: textEdit.nodePath,
+ if (action === null) {
+ return false;
+ }
+
+ const openTargetInEditor = async () => {
+ const originalLocation =
+ await resolveOriginalLocation(doubleClickTarget);
+ if (originalLocation === null) {
+ return;
+ }
+
+ await openOriginalPositionInEditor(originalLocation);
+ };
+
+ openTargetInEditor().catch((err) => {
+ showNotification((err as Error).message, 2000);
});
+
+ return true;
},
- [onSelect],
+ [previewServerState.type, resolveOriginalLocation],
);
const onContextMenuOpen = React.useCallback(async () => {
@@ -1584,22 +1607,7 @@ export const SelectedOutlineElement: React.FC<{
onSelect(target.selection, {shiftKey: false, toggleKey: false});
}
- const stack = target.sequence.getStack();
- let originalLocation: ResolvedStackLocation | null = null;
- if (stack) {
- try {
- originalLocation = await getOriginalLocationFromStack(
- stack,
- 'sequence',
- );
- } catch (err) {
- showNotification((err as Error).message, 2000);
- }
- }
-
- if (stack) {
- updateResolvedStackTrace(stack, originalLocation);
- }
+ const originalLocation = await resolveOriginalLocation(target);
const fileLocation = formatFileLocation({
location: originalLocation,
@@ -1746,11 +1754,11 @@ export const SelectedOutlineElement: React.FC<{
confirm,
onSelect,
previewServerState,
+ resolveOriginalLocation,
selectAsset,
setSelectedModal,
setPropStatuses,
target,
- updateResolvedStackTrace,
]);
return (
@@ -1767,7 +1775,7 @@ export const SelectedOutlineElement: React.FC<{
onHoverChange={onHoverChange}
onSnapPointsChange={onSnapPointsChange}
onSelect={onSelect}
- onTextEditStart={onTextEditStart}
+ onDoubleClickTarget={onDoubleClickTarget}
scale={scale}
snapTargets={snapTargets}
target={target}
diff --git a/packages/studio/src/components/SelectedOutlineOverlay.tsx b/packages/studio/src/components/SelectedOutlineOverlay.tsx
index b6de83607c..052d516a08 100644
--- a/packages/studio/src/components/SelectedOutlineOverlay.tsx
+++ b/packages/studio/src/components/SelectedOutlineOverlay.tsx
@@ -96,6 +96,7 @@ export {
snapSelectedOutlineUv,
} from './selected-outline-drag';
export {
+ getOutlineDoubleClickAction,
getOutlineSelectionInteraction,
getSelectedEffectFieldsBySequenceKey,
getSelectedOutlineRotationCornerInfo,
@@ -659,8 +660,6 @@ export const SelectedOutlineOverlay: React.FC<{
activeSchema?.[transformOriginFieldKey];
const transformOriginPropStatus =
nodePropStatuses?.[transformOriginFieldKey];
- const textContentFieldSchema = activeSchema?.children;
- const textContentPropStatus = nodePropStatuses?.children;
const transformOriginValueForRotation =
transformOriginFieldSchema?.type === 'transform-origin' &&
(transformOriginPropStatus?.status === 'static' ||
@@ -728,12 +727,6 @@ export const SelectedOutlineOverlay: React.FC<{
const canDropEffect =
previewServerState.type === 'connected' &&
controls?.supportsEffects === true;
- const canTextEdit =
- previewServerState.type === 'connected' &&
- controls !== null &&
- textContentFieldSchema?.type === 'text-content' &&
- textContentPropStatus !== undefined;
-
return {
key,
containsSelection,
@@ -860,12 +853,6 @@ export const SelectedOutlineOverlay: React.FC<{
),
}
: null,
- textEdit: canTextEdit
- ? {
- nodePath,
- propStatus: textContentPropStatus,
- }
- : null,
uvHandles: containsSelection
? getSelectedUvHandles({
propStatuses,
diff --git a/packages/studio/src/components/selected-outline-measurement.ts b/packages/studio/src/components/selected-outline-measurement.ts
index eeec393921..e0804cf1af 100644
--- a/packages/studio/src/components/selected-outline-measurement.ts
+++ b/packages/studio/src/components/selected-outline-measurement.ts
@@ -343,6 +343,15 @@ export const getOutlineSelectionInteraction = ({
toggleKey: metaKey || ctrlKey,
});
+export const getOutlineDoubleClickAction = ({
+ button,
+ canOpenInEditor,
+}: {
+ readonly button: number;
+ readonly canOpenInEditor: boolean;
+}): 'open-in-editor' | null =>
+ button === 0 && canOpenInEditor ? 'open-in-editor' : null;
+
type SelectedEffectFields = {
allFields: boolean;
fieldKeys: Set<string>;
diff --git a/packages/studio/src/components/selected-outline-types.ts b/packages/studio/src/components/selected-outline-types.ts
index ad773401ff..2f287d686c 100644
--- a/packages/studio/src/components/selected-outline-types.ts
+++ b/packages/studio/src/components/selected-outline-types.ts
@@ -1,5 +1,4 @@
import type {
- CanUpdateSequencePropStatus,
CanUpdateSequencePropStatusKeyframed,
CanUpdateSequencePropStatusStatic,
InteractivitySchema,
@@ -34,7 +33,6 @@ export type SelectedOutlineTarget = {
readonly scaleDrag: SelectedOutlineScaleDragTarget | null;
readonly rotationDrag: SelectedOutlineRotationDragTarget | null;
readonly transformOriginDrag: SelectedOutlineTransformOriginDragTarget | null;
- readonly textEdit: SelectedOutlineTextEditTarget | null;
readonly uvHandles: readonly SelectedOutlineUvHandle[];
};
@@ -44,11 +42,6 @@ export type SelectedOutlineEffectDropTarget = {
readonly nodePath: SequencePropsSubscriptionKey;
};
-export type SelectedOutlineTextEditTarget = {
- readonly nodePath: SequencePropsSubscriptionKey;
- readonly propStatus: CanUpdateSequencePropStatus;
-};
-
export type SelectedOutlineDragTarget = {
readonly propStatus:
| CanUpdateSequencePropStatusStatic
diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.ts
index 4628bea4bd..2e9e666e83 100644
--- a/packages/studio/src/test/timeline-selection.test.ts
+++ b/packages/studio/src/test/timeline-selection.test.ts
@@ -28,6 +28,7 @@ import {
applySelectedOutlineDragAxisLock,
applySelectedOutlineTransformOriginAxisLock,
compensateTranslateForTransformOrigin,
+ getOutlineDoubleClickAction,
getOutlineSelectionInteraction,
getSelectedEffectFieldsBySequenceKey,
getSelectedOutlineActiveSchema,
@@ -1804,6 +1805,18 @@ test('Canvas outline selection uses conventional modifier keys', () => {
).toEqual({shiftKey: false, toggleKey: true});
});
+test('Canvas outline double-click only handles opening the editor', () => {
+ expect(getOutlineDoubleClickAction({button: 0, canOpenInEditor: true})).toBe(
+ 'open-in-editor',
+ );
+ expect(getOutlineDoubleClickAction({button: 0, canOpenInEditor: false})).toBe(
+ null,
+ );
+ expect(
+ getOutlineDoubleClickAction({button: 2, canOpenInEditor: true}),
+ ).toBeNull();
+});
+
test('Canvas outline hit targets render nested sequences above parents', () => {
const schema = {} satisfies InteractivitySchema;
const refForOutline = {current: null};