Skip to content

Commit c99dabc

Browse files
committed
feat(studio): add M (mute) and Shift+L (loop) keyboard shortcuts
Adds NLE-style hotkeys for muting audio and toggling loop playback in the Studio player, matching the workflow conventions in DaVinci Resolve, Premiere, and Final Cut. - M toggles audio mute (no-op above 1x playback, matching the mute button's existing gating behavior). - Shift+L toggles loop. Ctrl/Cmd+L was considered but is filtered out by shouldIgnorePlaybackShortcutEvent and conflicts with the browser address bar; Shift+L is also consistent with the existing Shift+I / Shift+O modifier pattern. The Shift+L handler runs before the existing plain-L shuttle case so it doesn't also start forward playback. Fixes #905
1 parent da38de1 commit c99dabc

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

‎packages/studio/src/player/components/PlayerControls.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const SHORTCUT_SECTIONS = [
1515
{ key: "J", label: "Play backward" },
1616
{ key: "K", label: "Stop" },
1717
{ key: "L", label: "Play forward" },
18+
{ key: "M", label: "Toggle mute" },
19+
{ key: "⇧L", label: "Toggle loop" },
1820
{ key: "←/→", label: "Step 1 frame" },
1921
{ key: "⇧←/⇧→", label: "Step 10 frames" },
2022
],

‎packages/studio/src/player/hooks/usePlaybackKeyboard.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,58 @@ describe("usePlaybackKeyboard — keyboard layout independence (#834)", () => {
172172
expect(spies.play).toHaveBeenCalledTimes(1);
173173
});
174174
});
175+
176+
describe("usePlaybackKeyboard — mute & loop shortcuts (#905)", () => {
177+
it("M toggles audioMuted", () => {
178+
const { dispatch } = setupHook();
179+
expect(usePlayerStore.getState().audioMuted).toBe(false);
180+
181+
act(() => {
182+
dispatch(keydown({ code: "KeyM", key: "m" }));
183+
});
184+
expect(usePlayerStore.getState().audioMuted).toBe(true);
185+
186+
act(() => {
187+
dispatch(keydown({ code: "KeyM", key: "m" }));
188+
});
189+
expect(usePlayerStore.getState().audioMuted).toBe(false);
190+
});
191+
192+
it("M does NOT toggle audioMuted above 1x playback (matches button gating)", () => {
193+
const { dispatch } = setupHook();
194+
usePlayerStore.setState({ playbackRate: 2, audioMuted: false });
195+
196+
act(() => {
197+
dispatch(keydown({ code: "KeyM", key: "m" }));
198+
});
199+
200+
expect(usePlayerStore.getState().audioMuted).toBe(false);
201+
});
202+
203+
it("Shift+L toggles loopEnabled without starting forward shuttle", () => {
204+
const { dispatch, spies } = setupHook();
205+
expect(usePlayerStore.getState().loopEnabled).toBe(false);
206+
207+
act(() => {
208+
dispatch(keydown({ code: "KeyL", key: "L", shiftKey: true }));
209+
});
210+
expect(usePlayerStore.getState().loopEnabled).toBe(true);
211+
expect(spies.play).not.toHaveBeenCalled();
212+
213+
act(() => {
214+
dispatch(keydown({ code: "KeyL", key: "L", shiftKey: true }));
215+
});
216+
expect(usePlayerStore.getState().loopEnabled).toBe(false);
217+
});
218+
219+
it("Plain L still starts forward shuttle (regression guard)", () => {
220+
const { dispatch, spies } = setupHook();
221+
222+
act(() => {
223+
dispatch(keydown({ code: "KeyL", key: "l" }));
224+
});
225+
226+
expect(spies.play).toHaveBeenCalledTimes(1);
227+
expect(usePlayerStore.getState().loopEnabled).toBe(false);
228+
});
229+
});

‎packages/studio/src/player/hooks/usePlaybackKeyboard.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ export function usePlaybackKeyboard({
108108
return;
109109
}
110110
if (e.repeat) return;
111+
if (key === "m") {
112+
e.preventDefault();
113+
const state = usePlayerStore.getState();
114+
// Audio is force-muted above 1x playback — match the mute button's gating.
115+
if (state.playbackRate <= 1) {
116+
state.setAudioMuted(!state.audioMuted);
117+
}
118+
return;
119+
}
120+
if (key === "l" && e.shiftKey) {
121+
e.preventDefault();
122+
const state = usePlayerStore.getState();
123+
state.setLoopEnabled(!state.loopEnabled);
124+
return;
125+
}
111126
if (key === "k") {
112127
e.preventDefault();
113128
pause();

0 commit comments

Comments
 (0)