Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Double-click timeline list item to open in editor

Jonny Burgercd85eb08013f
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index 56de6dfb7a..992f5b6f72 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -4,7 +4,6 @@ import {Internals} from 'remotion';
import {NoReactInternals} from 'remotion/no-react';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
-import {openOriginalPositionInEditor} from '../../helpers/open-in-editor';
import {
getTimelineLayerHeight,
TIMELINE_ITEM_BORDER_BOTTOM,
@@ -33,11 +32,12 @@ import {
} from './TimelineMediaInfo';
import {TimelineRowChrome} from './TimelineRowChrome';
import {
+ SELECTION_ENABLED,
useTimelineRowContainsSelection,
useTimelineRowSelection,
} from './TimelineSelection';
import {TimelineSequenceName} from './TimelineSequenceName';
-import {useResolveStackAndReactToChange} from './use-resolved-stack-react-to-change';
+import {useOpenSequenceInEditor} from './use-open-sequence-in-editor';
const labelContainerStyle: React.CSSProperties = {
alignItems: 'center',
@@ -66,7 +66,8 @@ export const TimelineListItem: React.FC<{
useTimelineRowSelection(nodePathInfo);
const containsSelection = useTimelineRowContainsSelection(nodePathInfo);
- const originalLocation = useResolveStackAndReactToChange(sequence.getStack);
+ const {canOpenInEditor, openInEditor, originalLocation} =
+ useOpenSequenceInEditor(sequence);
const validatedLocation = useMemo(() => {
if (
@@ -155,9 +156,6 @@ export const TimelineListItem: React.FC<{
}
}, [nodePath, validatedLocation?.source, nodePathInfo]);
- const showInEditorDisabled =
- !window.remotion_editorName || !previewConnected || !originalLocation;
-
const mediaSrc =
sequence.type === 'audio' ||
sequence.type === 'video' ||
@@ -176,7 +174,7 @@ export const TimelineListItem: React.FC<{
}
const editorName = window.remotion_editorName;
- const documentationLink = sequence.documentationLink;
+ const {documentationLink} = sequence;
return [
editorName
@@ -186,17 +184,9 @@ export const TimelineListItem: React.FC<{
keyHint: null,
label: `Show in ${editorName}`,
leftItem: null,
- disabled: showInEditorDisabled,
- onClick: async () => {
- if (showInEditorDisabled || !originalLocation) {
- return;
- }
-
- try {
- await openOriginalPositionInEditor(originalLocation);
- } catch (err) {
- showNotification((err as Error).message, 2000);
- }
+ disabled: !canOpenInEditor,
+ onClick: () => {
+ openInEditor();
},
quickSwitcherLabel: null,
subMenu: null,
@@ -284,11 +274,11 @@ export const TimelineListItem: React.FC<{
duplicateDisabled,
onDeleteSequenceFromSource,
onDuplicateSequenceFromSource,
- originalLocation,
+ canOpenInEditor,
+ openInEditor,
previewConnected,
- sequence.documentationLink,
+ sequence,
setCanvasContent,
- showInEditorDisabled,
]);
const isExpanded =
@@ -302,6 +292,18 @@ export const TimelineListItem: React.FC<{
toggleTrack(nodePathInfo);
}, [nodePathInfo, toggleTrack]);
+ const onShowInEditorDoubleClick = useCallback(
+ (e: React.MouseEvent<HTMLDivElement>) => {
+ if (!SELECTION_ENABLED || !canOpenInEditor) {
+ return;
+ }
+
+ e.stopPropagation();
+ openInEditor();
+ },
+ [canOpenInEditor, openInEditor],
+ );
+
const codeValuesForOverride = useMemo(() => {
return nodePath
? Internals.getCodeValuesCtx(codeValues, nodePath)
@@ -427,6 +429,11 @@ export const TimelineListItem: React.FC<{
showSelectedBackground
containsSelection={containsSelection}
outerHeight={outerHeight}
+ onDoubleClick={
+ SELECTION_ENABLED && canOpenInEditor
+ ? onShowInEditorDoubleClick
+ : undefined
+ }
>
<div style={labelContainerStyle}>
<TimelineSequenceName
diff --git a/packages/studio/src/components/Timeline/TimelineRowChrome.tsx b/packages/studio/src/components/Timeline/TimelineRowChrome.tsx
index c9c0eb4cdc..ee3633c146 100644
--- a/packages/studio/src/components/Timeline/TimelineRowChrome.tsx
+++ b/packages/studio/src/components/Timeline/TimelineRowChrome.tsx
@@ -35,6 +35,7 @@ export const TimelineRowChrome: React.FC<{
// bottom track separator. The background highlight and click target span the
// outer (used by sequence rows whose layer is taller than the chrome row).
readonly outerHeight: number | null;
+ readonly onDoubleClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
}> = ({
depth,
eye,
@@ -47,6 +48,7 @@ export const TimelineRowChrome: React.FC<{
showSelectedBackground,
containsSelection,
outerHeight,
+ onDoubleClick,
}) => {
const indentWidth = getTimelineRowIndentWidth(depth);
@@ -115,6 +117,7 @@ export const TimelineRowChrome: React.FC<{
style={outerStyle}
onPointerDown={selectable ? onPointerDown : undefined}
onContextMenu={selectable ? onContextMenu : undefined}
+ onDoubleClick={onDoubleClick}
>
<div style={innerRowStyle}>{chrome}</div>
</div>
@@ -125,6 +128,7 @@ export const TimelineRowChrome: React.FC<{
<div
onPointerDown={selectable ? onPointerDown : undefined}
onContextMenu={selectable ? onContextMenu : undefined}
+ onDoubleClick={onDoubleClick}
style={innerRowStyle}
>
{chrome}
diff --git a/packages/studio/src/components/Timeline/use-open-sequence-in-editor.ts b/packages/studio/src/components/Timeline/use-open-sequence-in-editor.ts
new file mode 100644
index 0000000000..9f4a9ef8dd
--- /dev/null
+++ b/packages/studio/src/components/Timeline/use-open-sequence-in-editor.ts
@@ -0,0 +1,38 @@
+import {useCallback, useContext, useMemo} from 'react';
+import type {TSequence} from 'remotion';
+import {StudioServerConnectionCtx} from '../../helpers/client-id';
+import {openOriginalPositionInEditor} from '../../helpers/open-in-editor';
+import {showNotification} from '../Notifications/NotificationCenter';
+import {useResolveStackAndReactToChange} from './use-resolved-stack-react-to-change';
+
+export const useOpenSequenceInEditor = (sequence: TSequence) => {
+ const {previewServerState} = useContext(StudioServerConnectionCtx);
+ const previewConnected = previewServerState.type === 'connected';
+ const originalLocation = useResolveStackAndReactToChange(sequence.getStack);
+
+ const canOpenInEditor = useMemo(
+ () =>
+ Boolean(
+ window.remotion_editorName && previewConnected && originalLocation,
+ ),
+ [originalLocation, previewConnected],
+ );
+
+ const openInEditor = useCallback(async () => {
+ if (!canOpenInEditor || !originalLocation) {
+ return;
+ }
+
+ try {
+ await openOriginalPositionInEditor(originalLocation);
+ } catch (err) {
+ showNotification((err as Error).message, 2000);
+ }
+ }, [canOpenInEditor, originalLocation]);
+
+ return {
+ canOpenInEditor,
+ openInEditor,
+ originalLocation,
+ };
+};