Skip to content

πŸŽ₯ Make videos programmatically with React

Support standard redo shortcuts in Studio (#9705)

Igor Samokhovets04e0ddee59eb
diff --git a/packages/studio/src/components/KeyboardShortcutsExplainer.tsx b/packages/studio/src/components/KeyboardShortcutsExplainer.tsx
index 37732685a4..a87e7b9ad1 100644
--- a/packages/studio/src/components/KeyboardShortcutsExplainer.tsx
+++ b/packages/studio/src/components/KeyboardShortcutsExplainer.tsx
@@ -7,6 +7,7 @@ import {
WHITE,
WHITE_ALPHA_10,
} from '../helpers/colors';
+import {isMac} from '../helpers/is-mac';
import {getStudioAskAIEnabled} from '../helpers/studio-runtime-config';
import {areKeyboardShortcutsDisabled} from '../helpers/use-keybinding';
import {ArrowLeft, ArrowRight, ShiftIcon} from '../icons/keys';
@@ -320,7 +321,15 @@ export const KeyboardShortcutsExplainer: React.FC = () => {
<div style={left}>
<kbd style={key}>{cmdOrCtrlCharacter}</kbd>
<Spacing x={0.3} />
- <kbd style={key}>Y</kbd>
+ {isMac ? (
+ <>
+ <kbd style={key}>Shift</kbd>
+ <Spacing x={0.3} />
+ <kbd style={key}>Z</kbd>
+ </>
+ ) : (
+ <kbd style={key}>Y</kbd>
+ )}
</div>
<div style={right}>Redo</div>
</Row>
diff --git a/packages/studio/src/components/UndoRedoButtons.tsx b/packages/studio/src/components/UndoRedoButtons.tsx
index f9e85d8667..bd5f8fcf8a 100644
--- a/packages/studio/src/components/UndoRedoButtons.tsx
+++ b/packages/studio/src/components/UndoRedoButtons.tsx
@@ -8,6 +8,7 @@ import React, {
} from 'react';
import {cmdOrCtrlCharacter} from '../error-overlay/remotion-overlay/ShortcutHint';
import {StudioServerConnectionCtx} from '../helpers/client-id';
+import {isMac} from '../helpers/is-mac';
import {
areKeyboardShortcutsDisabled,
useKeybinding,
@@ -96,11 +97,15 @@ export const UndoRedoButtons: React.FC = () => {
keepRegisteredWhenNotHighestContext: false,
});
- const redo = keybindings.registerKeybinding({
+ const redoWithShiftZ = keybindings.registerKeybinding({
event: 'keydown',
- key: 'y',
+ key: 'z',
commandCtrlKey: true,
- callback: () => {
+ callback: (e) => {
+ if (!e.shiftKey) {
+ return;
+ }
+
if (redoFile) {
onRedo();
}
@@ -110,9 +115,26 @@ export const UndoRedoButtons: React.FC = () => {
keepRegisteredWhenNotHighestContext: false,
});
+ const redoWithY = isMac
+ ? null
+ : keybindings.registerKeybinding({
+ event: 'keydown',
+ key: 'y',
+ commandCtrlKey: true,
+ callback: () => {
+ if (redoFile) {
+ onRedo();
+ }
+ },
+ preventDefault: true,
+ triggerIfInputFieldFocused: false,
+ keepRegisteredWhenNotHighestContext: false,
+ });
+
return () => {
undo.unregister();
- redo.unregister();
+ redoWithShiftZ.unregister();
+ redoWithY?.unregister();
};
}, [keybindings, onRedo, onUndo, redoFile, undoFile]);
@@ -122,7 +144,9 @@ export const UndoRedoButtons: React.FC = () => {
const redoTooltip = areKeyboardShortcutsDisabled()
? 'Redo'
- : `Redo (${cmdOrCtrlCharacter}+Y)`;
+ : isMac
+ ? `Redo (${cmdOrCtrlCharacter}+Shift+Z)`
+ : `Redo (${cmdOrCtrlCharacter}+Y)`;
const renderUndo: RenderInlineAction = useCallback(
(color) => {
diff --git a/packages/studio/src/error-overlay/remotion-overlay/ShortcutHint.tsx b/packages/studio/src/error-overlay/remotion-overlay/ShortcutHint.tsx
index e499d6aaec..1f3f63d59f 100644
--- a/packages/studio/src/error-overlay/remotion-overlay/ShortcutHint.tsx
+++ b/packages/studio/src/error-overlay/remotion-overlay/ShortcutHint.tsx
@@ -1,10 +1,8 @@
import React, {useMemo} from 'react';
+import {isMac} from '../../helpers/is-mac';
import {areKeyboardShortcutsDisabled} from '../../helpers/use-keybinding';
-export const cmdOrCtrlCharacter =
- typeof window !== 'undefined' && window.navigator.platform.startsWith('Mac')
- ? '⌘'
- : 'Ctrl';
+export const cmdOrCtrlCharacter = isMac ? '⌘' : 'Ctrl';
const container: React.CSSProperties = {
display: 'inline-block',
diff --git a/packages/studio/src/helpers/is-mac.ts b/packages/studio/src/helpers/is-mac.ts
new file mode 100644
index 0000000000..825c796f68
--- /dev/null
+++ b/packages/studio/src/helpers/is-mac.ts
@@ -0,0 +1,2 @@
+export const isMac =
+ typeof window !== 'undefined' && window.navigator.platform.startsWith('Mac');
diff --git a/packages/studio/src/helpers/use-keybinding.ts b/packages/studio/src/helpers/use-keybinding.ts
index f62a63ac40..2bc6ee2ae8 100644
--- a/packages/studio/src/helpers/use-keybinding.ts
+++ b/packages/studio/src/helpers/use-keybinding.ts
@@ -2,6 +2,7 @@ import {useCallback, useContext, useEffect, useMemo, useState} from 'react';
import type {KeyEventType, RegisteredKeybinding} from '../state/keybindings';
import {KeybindingContext} from '../state/keybindings';
import {useZIndex} from '../state/z-index';
+import {isMac} from './is-mac';
import {getStudioKeyboardShortcutsEnabled} from './studio-runtime-config';
if (!getStudioKeyboardShortcutsEnabled()) {
@@ -43,9 +44,7 @@ export const useKeybinding = () => {
}
const listener = (e: KeyboardEvent) => {
- const commandKey = window.navigator.platform.startsWith('Mac')
- ? e.metaKey
- : e.ctrlKey;
+ const commandKey = isMac ? e.metaKey : e.ctrlKey;
// Apparently, e.key can be undefined in Edge:
// https://github.com/remotion-dev/remotion/issues/5637