Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Use shortcut action menus

JonnyBurger7656dafb1237
diff --git a/packages/example/e2e/studio.test.mts b/packages/example/e2e/studio.test.mts
index d66d78a6ad..8804df8d99 100644
--- a/packages/example/e2e/studio.test.mts
+++ b/packages/example/e2e/studio.test.mts
@@ -1845,27 +1845,14 @@ test.describe('visual mode', () => {
const fixedShortcutRow = dialog
.getByRole('listitem')
.filter({hasText: '1 second back'});
- const fixedShortcutBox = await fixedShortcutRow
- .locator('kbd')
- .last()
- .boundingBox();
- const fixedLabelBox = await fixedShortcutRow
- .getByText('Fixed', {exact: true})
- .boundingBox();
- if (fixedShortcutBox === null || fixedLabelBox === null) {
- throw new Error('Expected shortcut and Fixed label to have boxes');
- }
-
- expect(
- Math.abs(
- fixedShortcutBox.y +
- fixedShortcutBox.height / 2 -
- (fixedLabelBox.y + fixedLabelBox.height / 2),
- ),
- ).toBeLessThan(1);
+ await expect(fixedShortcutRow.getByRole('button')).toHaveCount(0);
const playPauseShortcut = dialog.getByRole('button', {
name: 'Change shortcut for Play / Pause',
});
+ const playPauseActions = dialog.getByRole('button', {
+ name: 'Actions for Play / Pause',
+ });
+ await expect(playPauseActions).toBeVisible();
await playPauseShortcut.click();
await expect(playPauseShortcut).toContainText('Press shortcut');
await page.keyboard.press('q');
@@ -1873,10 +1860,11 @@ test.describe('visual mode', () => {
.poll(() => fs.readFileSync(configFile, 'utf8'))
.toContain('Config.setKeyboardShortcuts({');
await expect(playPauseShortcut).toContainText('Q');
- await dialog.getByTitle('Reset to default', {exact: true}).click();
+ await playPauseActions.click();
+ await page.getByText('Reset to default', {exact: true}).click();
await expect
.poll(() => fs.readFileSync(configFile, 'utf8'))
- .not.toContain('Config.setKeyboardShortcuts');
+ .not.toContain("'playPause'");
await expect(playPauseShortcut).toContainText('Space');
await dialog.getByRole('button', {name: 'Studio', exact: true}).click();
diff --git a/packages/studio/src/components/KeyboardShortcutsSettings.tsx b/packages/studio/src/components/KeyboardShortcutsSettings.tsx
index b4744b2362..0a3a66b20a 100644
--- a/packages/studio/src/components/KeyboardShortcutsSettings.tsx
+++ b/packages/studio/src/components/KeyboardShortcutsSettings.tsx
@@ -15,7 +15,9 @@ import {
WHITE,
} from '../helpers/colors';
import {getStudioAskAIEnabled} from '../helpers/studio-runtime-config';
+import {CaretDown} from '../icons/caret';
import {booleanOptions, ConfigSelect} from './ConfigSelect';
+import {InlineDropdown} from './InlineDropdown';
import {sectionHeader} from './InspectorPanel/styles';
import {
askAIKeyboardShortcutGroup,
@@ -25,6 +27,7 @@ import {
shortcutFromKeyboardEvent,
} from './keyboard-shortcuts';
import {Spacing} from './layout';
+import type {ComboboxValue} from './NewComposition/ComboBox';
import {ValidationMessage} from './NewComposition/ValidationMessage';
import {useSettings} from './SettingsContext';
import {useAutoSaveConfig} from './use-auto-save-config';
@@ -53,7 +56,7 @@ const shortcutRow: React.CSSProperties = {
borderBottom: BORDER_WHITE_ALPHA_12,
columnGap: 12,
display: 'grid',
- gridTemplateColumns: 'minmax(0, 1fr) minmax(76px, max-content) 94px',
+ gridTemplateColumns: 'minmax(0, 1fr) minmax(76px, max-content) 24px',
margin: '0 16px',
minHeight: 42,
};
@@ -123,21 +126,6 @@ const chordButton: React.CSSProperties = {
padding: '4px 0',
};
-const smallButton: React.CSSProperties = {
- background: 'transparent',
- border: 0,
- color: LIGHT_TEXT,
- cursor: 'pointer',
- fontSize: 11,
- padding: '4px',
-};
-
-const fixedLabel: React.CSSProperties = {
- color: LIGHT_TEXT,
- fontSize: 11,
- padding: '4px',
-};
-
const alternative: React.CSSProperties = {
color: LIGHT_TEXT,
fontSize: 11,
@@ -296,6 +284,54 @@ export const KeyboardShortcutsSettings: React.FC = () => {
shortcut.actionId,
configuredShortcuts,
).map(formatKeyboardShortcut);
+ const shortcutMenuItems: ComboboxValue[] =
+ shortcut.actionId === null
+ ? []
+ : [
+ ...(configured
+ ? [
+ {
+ id: 'reset-shortcut',
+ keyHint: null,
+ label: 'Reset to default',
+ leftItem: null,
+ onClick: () => {
+ setConfiguredShortcuts((current) => {
+ const next = {...current};
+ delete next[shortcut.actionId!];
+ return next;
+ });
+ setShortcutsEdited(true);
+ },
+ quickSwitcherLabel: null,
+ subMenu: null,
+ type: 'item' as const,
+ value: 'reset-shortcut',
+ },
+ ]
+ : []),
+ ...(configuredShortcuts[shortcut.actionId] !== null
+ ? [
+ {
+ id: 'disable-shortcut',
+ keyHint: null,
+ label: 'Disable shortcut',
+ leftItem: null,
+ onClick: () => {
+ setConfiguredShortcuts((current) => ({
+ ...current,
+ [shortcut.actionId!]: null,
+ }));
+ setShortcutsEdited(true);
+ },
+ quickSwitcherLabel: null,
+ subMenu: null,
+ type: 'item' as const,
+ value: 'disable-shortcut',
+ },
+ ]
+ : []),
+ ];
return (
<div
@@ -314,13 +350,7 @@ export const KeyboardShortcutsSettings: React.FC = () => {
<span style={shortcutCell}>
<ShortcutChords values={shortcutValues} />
</span>
- <span style={actionCell}>
- {shortcut.actionId === null ? (
- <span style={fixedLabel} title={shortcut.fixedReason}>
- Fixed
- </span>
- ) : null}
- </span>
+ <span />
</>
) : (
<>
@@ -382,39 +412,12 @@ export const KeyboardShortcutsSettings: React.FC = () => {
</button>
</span>
<span style={actionCell}>
- {configured ? (
- <button
- type="button"
- style={smallButton}
- title="Reset to default"
- onClick={() => {
- setConfiguredShortcuts((current) => {
- const next = {...current};
- delete next[shortcut.actionId!];
- return next;
- });
- setShortcutsEdited(true);
- }}
- >
- Reset
- </button>
- ) : null}
- {configuredShortcuts[shortcut.actionId] !== null ? (
- <button
- type="button"
- style={smallButton}
- title="Disable shortcut"
- onClick={() => {
- setConfiguredShortcuts((current) => ({
- ...current,
- [shortcut.actionId!]: null,
- }));
- setShortcutsEdited(true);
- }}
- >
- Disable
- </button>
- ) : null}
+ <InlineDropdown
+ renderAction={(color) => <CaretDown color={color} />}
+ title={`Actions for ${shortcut.action}`}
+ values={shortcutMenuItems}
+ variant={null}
+ />
</span>
</>
)}