Skip to content

🎥 Make videos programmatically with React

Fix sequence context menu dividers

JonnyBurger898c40dd78ba
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
index 1bcbf45d36..b0f7b1f4b6 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
@@ -898,7 +898,7 @@ export const TimelineSequenceItem: React.FC<{
{
type: 'item' as const,
id: 'rename-sequence',
- keyHint: 'Enter',
+ keyHint: null,
label: 'Rename...',
leftItem: null,
disabled: !canRenameThisSequence,
diff --git a/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts b/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts
index 9dcad807b2..6658986e6d 100644
--- a/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts
+++ b/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts
@@ -5,6 +5,27 @@ import {showNotification} from '../Notifications/NotificationCenter';
import type {TimelineAssetLinkInfo} from './timeline-asset-link';
import {openTimelineAssetLink} from './timeline-asset-link';
+const normalizeMenuDividers = (items: ComboboxValue[]): ComboboxValue[] => {
+ const normalized: ComboboxValue[] = [];
+
+ for (const item of items) {
+ if (item.type === 'divider') {
+ const previousItem = normalized[normalized.length - 1];
+ if (!previousItem || previousItem.type === 'divider') {
+ continue;
+ }
+ }
+
+ normalized.push(item);
+ }
+
+ if (normalized[normalized.length - 1]?.type === 'divider') {
+ normalized.pop();
+ }
+
+ return normalized;
+};
+
export const getSequenceContextMenuItems = ({
assetLinkInfo,
canOpenInEditor,
@@ -41,7 +62,7 @@ export const getSequenceContextMenuItems = ({
const editorName = window.remotion_editorName;
const {documentationLink} = sequence;
- return [
+ const items = [
editorName
? {
type: 'item' as const,
@@ -176,4 +197,6 @@ export const getSequenceContextMenuItems = ({
}
: null,
].filter(NoReactInternals.truthy);
+
+ return normalizeMenuDividers(items);
};
diff --git a/packages/studio/src/test/sequence-context-menu-items.test.ts b/packages/studio/src/test/sequence-context-menu-items.test.ts
new file mode 100644
index 0000000000..edefd68df6
--- /dev/null
+++ b/packages/studio/src/test/sequence-context-menu-items.test.ts
@@ -0,0 +1,92 @@
+import {afterEach, expect, test} from 'bun:test';
+import type {TSequence} from 'remotion';
+import type {ComboboxValue} from '../components/NewComposition/ComboBox';
+import {getSequenceContextMenuItems} from '../components/Timeline/get-sequence-context-menu-items';
+
+const originalWindowDescriptor = Object.getOwnPropertyDescriptor(
+ globalThis,
+ 'window',
+);
+
+afterEach(() => {
+ if (originalWindowDescriptor) {
+ Object.defineProperty(globalThis, 'window', originalWindowDescriptor);
+ return;
+ }
+
+ Reflect.deleteProperty(globalThis, 'window');
+});
+
+const installTestWindow = () => {
+ const testWindow: Pick<Window, 'open' | 'remotion_editorName'> = {
+ open: () => null,
+ remotion_editorName: null,
+ };
+
+ Object.defineProperty(globalThis, 'window', {
+ configurable: true,
+ value: testWindow,
+ });
+};
+
+const renameSequenceItem: ComboboxValue = {
+ type: 'item',
+ id: 'rename-sequence',
+ keyHint: null,
+ label: 'Rename...',
+ leftItem: null,
+ disabled: false,
+ onClick: () => undefined,
+ quickSwitcherLabel: null,
+ subMenu: null,
+ value: 'rename-sequence',
+};
+
+const noop = () => undefined;
+
+const expectNoExtraDividers = (items: ComboboxValue[]) => {
+ expect(items[0]?.type).not.toBe('divider');
+ expect(items[items.length - 1]?.type).not.toBe('divider');
+
+ for (let i = 1; i < items.length; i++) {
+ expect([items[i - 1].type, items[i].type]).not.toEqual([
+ 'divider',
+ 'divider',
+ ]);
+ }
+};
+
+test('sequence context menu does not put two dividers between docs and rename', () => {
+ installTestWindow();
+
+ const items = getSequenceContextMenuItems({
+ assetLinkInfo: null,
+ canOpenInEditor: false,
+ deleteDisabled: false,
+ disableInteractivityDisabled: false,
+ duplicateDisabled: false,
+ fileLocation: 'src/Video.tsx:10:2',
+ includeSourceEditItems: true,
+ onDeleteSequenceFromSource: noop,
+ onDisableSequenceInteractivity: noop,
+ onDuplicateSequenceFromSource: noop,
+ openInEditor: noop,
+ originalLocation: null,
+ selectAsset: noop,
+ sequence: {
+ documentationLink: 'https://www.remotion.dev/docs/sequence',
+ } as TSequence,
+ sourceActions: [renameSequenceItem],
+ });
+
+ expectNoExtraDividers(items);
+
+ const docsIndex = items.findIndex(
+ (item) => item.id === 'open-component-docs',
+ );
+ const renameIndex = items.findIndex((item) => item.id === 'rename-sequence');
+
+ expect(
+ items.slice(docsIndex + 1, renameIndex).map((item) => item.type),
+ ).toEqual(['divider']);
+});