@hyperframes/studio 0.8.230 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{hyperframes-player-Dv5Ew1Dr.js → hyperframes-player-z-8ElsHL.js} +1 -1
- package/dist/assets/{index-hiL49K7x.js → index-CBZs_Rm3.js} +1 -1
- package/dist/assets/{index-BvqtI0ko.js → index-M-AHqD2Z.js} +153 -153
- package/dist/index.d.ts +40 -0
- package/dist/index.html +1 -1
- package/dist/index.js +530 -432
- package/package.json +8 -8
- package/src/captions/components/CaptionOverlay.tsx +7 -14
- package/src/captions/keyboard.test.ts +12 -1
- package/src/captions/keyboard.ts +8 -8
- package/src/components/EditorShell.tsx +2 -1
- package/src/components/TimelineToolbar.tsx +2 -3
- package/src/components/editor/InspectorHeaderActions.tsx +3 -1
- package/src/components/editor/PropertyPanelFlatHeader.tsx +3 -1
- package/src/components/editor/SnapToolbar.tsx +3 -3
- package/src/components/editor/domEditNudge.test.ts +17 -1
- package/src/components/editor/domEditNudge.ts +16 -13
- package/src/components/editor/marqueeCommit.ts +2 -1
- package/src/hooks/appHotkeysDispatch.ts +94 -107
- package/src/hooks/linkShortcuts.test.ts +20 -0
- package/src/hooks/linkShortcuts.ts +11 -11
- package/src/hooks/useAppHotkeys.test.ts +143 -0
- package/src/hooks/useAppHotkeys.ts +1 -4
- package/src/hooks/useAutomationSelectionKeyboard.ts +7 -18
- package/src/hooks/useKeyframeKeyboard.ts +2 -3
- package/src/hooks/useTimelineDeleteOps.ts +2 -1
- package/src/player/components/BeatStrip.tsx +2 -1
- package/src/player/components/ClipContextMenu.tsx +3 -3
- package/src/player/components/TimelineClipFades.tsx +2 -1
- package/src/player/components/clipMenuLinkItems.tsx +5 -4
- package/src/player/components/studioCombo.test.ts +99 -0
- package/src/player/components/studioCombo.ts +108 -0
- package/src/player/components/studioShortcuts.test.tsx +16 -1
- package/src/player/components/studioShortcuts.ts +85 -29
- package/src/player/components/timelineClipDragGestureLifecycle.ts +2 -1
- package/src/player/components/timelineEditing.ts +2 -2
- package/src/player/components/useTimelineClipDrag.ts +2 -1
- package/src/player/components/useTimelineKeyboardActor.ts +7 -18
- package/src/player/components/useTimelineKeyframeHandlers.ts +2 -1
- package/src/player/components/useTimelineRangeSelection.ts +3 -2
- package/src/player/hooks/usePlaybackKeyboard.test.ts +87 -4
- package/src/player/hooks/usePlaybackKeyboard.ts +78 -82
- package/src/player/hooks/useTimelinePlayer.test.ts +19 -13
- package/src/player/lib/playbackShortcuts.ts +13 -16
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
3
|
import { usePlayerStore, type TimelineElement } from "../player";
|
|
4
4
|
import { dispatchLinkShortcut } from "./linkShortcuts";
|
|
5
|
+
import { setStudioKeys } from "../player/components/studioShortcuts";
|
|
5
6
|
|
|
6
7
|
const clip = (id: string, tag: string, extra: Partial<TimelineElement> = {}): TimelineElement => ({
|
|
7
8
|
id,
|
|
@@ -84,3 +85,22 @@ describe("dispatchLinkShortcut", () => {
|
|
|
84
85
|
expect(event.preventDefault).not.toHaveBeenCalled();
|
|
85
86
|
});
|
|
86
87
|
});
|
|
88
|
+
|
|
89
|
+
describe("dispatchLinkShortcut: remapped combos", () => {
|
|
90
|
+
afterEach(() => setStudioKeys(null));
|
|
91
|
+
|
|
92
|
+
it("link, detach and delete-one follow the map and the old combos go dead", () => {
|
|
93
|
+
setStudioKeys({ linkToggle: "mod+u", detachAudio: "alt+shift+u", deleteLinked: "alt+x" });
|
|
94
|
+
const video = clip("talk", "video", { muted: true, link: "lk-1", hasAudio: true });
|
|
95
|
+
select([video, clip("talk-audio", "audio", { link: "lk-1" })], "talk");
|
|
96
|
+
const handleLinkEdit = vi.fn();
|
|
97
|
+
const handleTimelineElementDeleteOnly = vi.fn();
|
|
98
|
+
const cb = { handleLinkEdit, handleTimelineElementDeleteOnly };
|
|
99
|
+
expect(dispatchLinkShortcut(key({ metaKey: true, key: "l" }), cb)).toBe(false);
|
|
100
|
+
expect(dispatchLinkShortcut(key({ metaKey: true, key: "u" }), cb)).toBe(true);
|
|
101
|
+
expect(handleLinkEdit).toHaveBeenCalledTimes(1);
|
|
102
|
+
expect(dispatchLinkShortcut(key({ altKey: true, key: "Backspace" }), cb)).toBe(false);
|
|
103
|
+
expect(dispatchLinkShortcut(key({ altKey: true, key: "≈", code: "KeyX" }), cb)).toBe(true);
|
|
104
|
+
expect(handleTimelineElementDeleteOnly).toHaveBeenCalledWith(video);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -2,24 +2,24 @@ import { usePlayerStore } from "../player";
|
|
|
2
2
|
import type { TimelineEditCallbacks } from "../player/components/timelineCallbacks";
|
|
3
3
|
import { resolveLinkMenuItems } from "../player/components/clipMenuLinkItems";
|
|
4
4
|
import { isTypingTarget } from "../utils/typingTarget";
|
|
5
|
+
import { keyHint, matchesKey } from "../player/components/studioShortcuts";
|
|
5
6
|
|
|
6
7
|
export interface LinkShortcutCallbacks {
|
|
7
8
|
handleLinkEdit?: TimelineEditCallbacks["onLinkEdit"];
|
|
8
9
|
handleTimelineElementDeleteOnly?: TimelineEditCallbacks["onDeleteElementOnly"];
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
const
|
|
12
|
-
|
|
12
|
+
const ACTIONS = [
|
|
13
|
+
["linkToggle", "linkToggle"],
|
|
14
|
+
["detachAudio", "detachAudio"],
|
|
15
|
+
["deleteLinked", "deleteLinked"],
|
|
16
|
+
["deleteLinkedAlt", "deleteLinked"],
|
|
17
|
+
] as const;
|
|
13
18
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
function shortcutOf(event: KeyboardEvent): string | null {
|
|
21
|
-
return SHORTCUTS.find(([, matches]) => matches(event))?.[0] ?? null;
|
|
22
|
-
}
|
|
19
|
+
const shortcutOf = (event: KeyboardEvent): string | null => {
|
|
20
|
+
const hit = ACTIONS.find(([action]) => matchesKey(event, action));
|
|
21
|
+
return hit ? keyHint(hit[1]) : null;
|
|
22
|
+
};
|
|
23
23
|
|
|
24
24
|
/** ⌘L unlink/link, ⌥⇧D detach audio, ⌥⌫ delete one linked clip — the clip menu's shortcuts. */
|
|
25
25
|
export function dispatchLinkShortcut(event: KeyboardEvent, cb: LinkShortcutCallbacks): boolean {
|
|
@@ -6,6 +6,7 @@ import type { DomEditSelection } from "../components/editor/domEditing";
|
|
|
6
6
|
import { clearAutomationClipboard, copyRange } from "../player/components/automationClipboard";
|
|
7
7
|
import { VOLUME_RANGE } from "@hyperframes/core/audio-automation";
|
|
8
8
|
import type { TimelineElement } from "../player/store/timelineElement";
|
|
9
|
+
import { useDockLayoutStore } from "../components/dock/dockLayoutStore";
|
|
9
10
|
import { setStudioKeys } from "../player/components/studioShortcuts";
|
|
10
11
|
import { useAudioGainDialogStore } from "../player/components/audioGainDialogStore";
|
|
11
12
|
import {
|
|
@@ -641,3 +642,145 @@ describe("editor keys the host can remap", () => {
|
|
|
641
642
|
expect(split.defaultPrevented).toBe(true);
|
|
642
643
|
});
|
|
643
644
|
});
|
|
645
|
+
|
|
646
|
+
describe("every app shortcut is a remappable combo", () => {
|
|
647
|
+
const dock = vi.fn();
|
|
648
|
+
const ev = (init: KeyboardEventInit) =>
|
|
649
|
+
new KeyboardEvent("keydown", { bubbles: true, cancelable: true, ...init });
|
|
650
|
+
const select = () => {
|
|
651
|
+
usePlayerStore.setState({ elements: [bgmElement], selectedElementId: "bgm" });
|
|
652
|
+
};
|
|
653
|
+
const rows: Array<{
|
|
654
|
+
action: string;
|
|
655
|
+
combo: string;
|
|
656
|
+
press: KeyboardEventInit;
|
|
657
|
+
moved: KeyboardEventInit;
|
|
658
|
+
hit: (cb: ReturnType<typeof callbacks>) => unknown;
|
|
659
|
+
}> = [
|
|
660
|
+
{
|
|
661
|
+
action: "undo",
|
|
662
|
+
combo: "mod+u",
|
|
663
|
+
press: { key: "z", metaKey: true },
|
|
664
|
+
moved: { key: "u", metaKey: true },
|
|
665
|
+
hit: (c) => c.handleUndo,
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
action: "redo",
|
|
669
|
+
combo: "mod+shift+u",
|
|
670
|
+
press: { key: "z", metaKey: true, shiftKey: true },
|
|
671
|
+
moved: { key: "u", metaKey: true, shiftKey: true },
|
|
672
|
+
hit: (c) => c.handleRedo,
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
action: "redoAlt",
|
|
676
|
+
combo: "ctrl+shift+y",
|
|
677
|
+
press: { key: "y", ctrlKey: true },
|
|
678
|
+
moved: { key: "y", ctrlKey: true, shiftKey: true },
|
|
679
|
+
hit: (c) => c.handleRedo,
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
action: "copy",
|
|
683
|
+
combo: "mod+shift+c",
|
|
684
|
+
press: { key: "c", metaKey: true },
|
|
685
|
+
moved: { key: "c", metaKey: true, shiftKey: true },
|
|
686
|
+
hit: (c) => c.handleCopy,
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
action: "paste",
|
|
690
|
+
combo: "mod+shift+v",
|
|
691
|
+
press: { key: "v", metaKey: true },
|
|
692
|
+
moved: { key: "v", metaKey: true, shiftKey: true },
|
|
693
|
+
hit: (c) => c.handlePaste,
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
action: "cut",
|
|
697
|
+
combo: "mod+shift+x",
|
|
698
|
+
press: { key: "x", metaKey: true },
|
|
699
|
+
moved: { key: "x", metaKey: true, shiftKey: true },
|
|
700
|
+
hit: (c) => c.handleCut,
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
action: "duplicate",
|
|
704
|
+
combo: "mod+shift+d",
|
|
705
|
+
press: { key: "d", metaKey: true },
|
|
706
|
+
moved: { key: "d", metaKey: true, shiftKey: true },
|
|
707
|
+
hit: (c) => c.handleDuplicate,
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
action: "group",
|
|
711
|
+
combo: "mod+shift+k",
|
|
712
|
+
press: { key: "g", metaKey: true },
|
|
713
|
+
moved: { key: "k", metaKey: true, shiftKey: true },
|
|
714
|
+
hit: (c) => c.onGroupSelection,
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
action: "ungroup",
|
|
718
|
+
combo: "mod+shift+j",
|
|
719
|
+
press: { key: "g", metaKey: true, shiftKey: true },
|
|
720
|
+
moved: { key: "j", metaKey: true, shiftKey: true },
|
|
721
|
+
hit: (c) => c.onUngroupSelection,
|
|
722
|
+
},
|
|
723
|
+
{
|
|
724
|
+
action: "tabCompositions",
|
|
725
|
+
combo: "mod+3",
|
|
726
|
+
press: { key: "1", metaKey: true },
|
|
727
|
+
moved: { key: "3", metaKey: true },
|
|
728
|
+
hit: () => dock,
|
|
729
|
+
},
|
|
730
|
+
];
|
|
731
|
+
|
|
732
|
+
beforeEach(() => {
|
|
733
|
+
dock.mockClear();
|
|
734
|
+
useDockLayoutStore.setState({ activatePanel: dock });
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
it.each(rows)("$action answers its default and only its new combo once moved", (row) => {
|
|
738
|
+
for (const [init, expected] of [
|
|
739
|
+
[row.press, true],
|
|
740
|
+
[row.moved, false],
|
|
741
|
+
] as const) {
|
|
742
|
+
select();
|
|
743
|
+
const cb = callbacks({ handleCopy: vi.fn(() => true) });
|
|
744
|
+
dispatchModifierKey(ev(init), (init.key ?? "").toLowerCase(), cb);
|
|
745
|
+
expect(Boolean(vi.mocked(row.hit(cb) as never).mock.calls.length), row.action).toBe(expected);
|
|
746
|
+
dock.mockClear();
|
|
747
|
+
}
|
|
748
|
+
setStudioKeys({ [row.action]: row.combo } as never);
|
|
749
|
+
for (const [init, expected] of [
|
|
750
|
+
[row.press, false],
|
|
751
|
+
[row.moved, true],
|
|
752
|
+
] as const) {
|
|
753
|
+
select();
|
|
754
|
+
const cb = callbacks({ handleCopy: vi.fn(() => true) });
|
|
755
|
+
dispatchModifierKey(ev(init), (init.key ?? "").toLowerCase(), cb);
|
|
756
|
+
expect(Boolean(vi.mocked(row.hit(cb) as never).mock.calls.length), row.action).toBe(expected);
|
|
757
|
+
dock.mockClear();
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
it("Delete, Backspace and the cancel key are combos too", () => {
|
|
762
|
+
select();
|
|
763
|
+
let cb = callbacks();
|
|
764
|
+
dispatchPlainKey(ev({ key: "Delete", code: "Delete" }), "delete", cb);
|
|
765
|
+
expect(cb.handleTimelineElementsDelete).toHaveBeenCalledTimes(1);
|
|
766
|
+
setStudioKeys({ deleteSelected: "x", deleteSelectedAlt: "shift+x" });
|
|
767
|
+
cb = callbacks();
|
|
768
|
+
dispatchPlainKey(ev({ key: "Delete", code: "Delete" }), "delete", cb);
|
|
769
|
+
dispatchPlainKey(ev({ key: "Backspace", code: "Backspace" }), "backspace", cb);
|
|
770
|
+
expect(cb.handleTimelineElementsDelete).not.toHaveBeenCalled();
|
|
771
|
+
dispatchPlainKey(ev({ key: "x", code: "KeyX" }), "x", cb);
|
|
772
|
+
expect(cb.handleTimelineElementsDelete).toHaveBeenCalledTimes(1);
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
it("cancel (Escape by default) returns the armed razor to select, and only the new key does once moved", () => {
|
|
776
|
+
usePlayerStore.getState().setActiveTool("razor");
|
|
777
|
+
dispatchPlainKey(ev({ key: "Escape", code: "Escape" }), "escape", callbacks());
|
|
778
|
+
expect(usePlayerStore.getState().activeTool).toBe("select");
|
|
779
|
+
setStudioKeys({ cancel: "q" });
|
|
780
|
+
usePlayerStore.getState().setActiveTool("razor");
|
|
781
|
+
dispatchPlainKey(ev({ key: "Escape", code: "Escape" }), "escape", callbacks());
|
|
782
|
+
expect(usePlayerStore.getState().activeTool).toBe("razor");
|
|
783
|
+
dispatchPlainKey(ev({ key: "q", code: "KeyQ" }), "q", callbacks());
|
|
784
|
+
expect(usePlayerStore.getState().activeTool).toBe("select");
|
|
785
|
+
});
|
|
786
|
+
});
|
|
@@ -226,10 +226,7 @@ export function useAppHotkeys({
|
|
|
226
226
|
const cb = cbRef.current;
|
|
227
227
|
const key = event.key.toLowerCase();
|
|
228
228
|
if (dispatchLinkShortcut(event, cb)) return;
|
|
229
|
-
if (event
|
|
230
|
-
dispatchModifierKey(event, key, cb);
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
229
|
+
if (dispatchModifierKey(event, key, cb)) return;
|
|
233
230
|
dispatchPlainKey(event, key, cb);
|
|
234
231
|
}, []);
|
|
235
232
|
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
} from "@hyperframes/core/audio-automation";
|
|
33
33
|
import { clampNumber } from "../utils/studioHelpers";
|
|
34
34
|
import { isTypingTarget } from "../utils/typingTarget";
|
|
35
|
+
import { matchesKey } from "../player/components/studioShortcuts";
|
|
35
36
|
import type { AutomationSelection } from "../player/store/automationSelectionSlice";
|
|
36
37
|
import type {
|
|
37
38
|
AutomationLaneBinding,
|
|
@@ -40,17 +41,6 @@ import type {
|
|
|
40
41
|
|
|
41
42
|
type PlayerState = ReturnType<typeof usePlayerStore.getState>;
|
|
42
43
|
|
|
43
|
-
/**
|
|
44
|
-
* A Cmd/Ctrl+<letter> chord. `e.key` is normalised because CapsLock makes it
|
|
45
|
-
* "V"/"C", and useAppHotkeys already lowercases — a raw `e.key === "v"` test
|
|
46
|
-
* would silently drop the keystroke here while that dispatcher still acted on
|
|
47
|
-
* it. Shift and Alt are excluded for the same parity reason (useAppHotkeys
|
|
48
|
-
* gates its own copy/paste on `!shiftKey && !altKey`).
|
|
49
|
-
*/
|
|
50
|
-
function isChord(e: KeyboardEvent, letter: string): boolean {
|
|
51
|
-
return (e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey && e.key.toLowerCase() === letter;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
44
|
/** A `TimelineElement`'s identity as the selection and lane bindings key by. */
|
|
55
45
|
function elementKeyOf(element: TimelineElement): string {
|
|
56
46
|
return element.key ?? element.id;
|
|
@@ -221,7 +211,7 @@ function handlePaste(
|
|
|
221
211
|
state: PlayerState,
|
|
222
212
|
lanes: UseAutomationLanesResult,
|
|
223
213
|
): boolean {
|
|
224
|
-
if (!
|
|
214
|
+
if (!matchesKey(e, "paste")) return false;
|
|
225
215
|
const clip = readClipboard(state.timelineProjectId);
|
|
226
216
|
if (!clip) return false;
|
|
227
217
|
const sel = state.automationSelection;
|
|
@@ -271,7 +261,7 @@ function handleCopy(
|
|
|
271
261
|
lanes: UseAutomationLanesResult,
|
|
272
262
|
sel: AutomationSelection,
|
|
273
263
|
): boolean {
|
|
274
|
-
if (!
|
|
264
|
+
if (!matchesKey(e, "copy")) return false;
|
|
275
265
|
const ctx = resolveSelectionContext(state, lanes, sel);
|
|
276
266
|
if (!ctx) return false;
|
|
277
267
|
if (!copyRange(state.timelineProjectId, ctx.lane, ctx.range, sel.t0, sel.t1)) return false;
|
|
@@ -298,8 +288,8 @@ function handleCopy(
|
|
|
298
288
|
export function automationOwnsKey(e: KeyboardEvent): boolean {
|
|
299
289
|
if (isTypingTarget(document.activeElement)) return false;
|
|
300
290
|
const state = usePlayerStore.getState();
|
|
301
|
-
if (
|
|
302
|
-
if (!
|
|
291
|
+
if (matchesKey(e, "copy")) return state.automationSelection !== null;
|
|
292
|
+
if (!matchesKey(e, "paste")) return false;
|
|
303
293
|
const clip = readClipboard(state.timelineProjectId);
|
|
304
294
|
if (!clip) return false;
|
|
305
295
|
const element = findElement(state.elements, state.selectedElementId);
|
|
@@ -317,8 +307,7 @@ function handleDelete(
|
|
|
317
307
|
lanes: UseAutomationLanesResult,
|
|
318
308
|
sel: AutomationSelection,
|
|
319
309
|
): boolean {
|
|
320
|
-
|
|
321
|
-
if (!isDeleteKey || e.metaKey || e.ctrlKey) return false;
|
|
310
|
+
if (!matchesKey(e, "deleteSelected") && !matchesKey(e, "deleteSelectedAlt")) return false;
|
|
322
311
|
const write = resolveDeleteWrite(state, lanes, sel);
|
|
323
312
|
if (!write) return false;
|
|
324
313
|
e.preventDefault();
|
|
@@ -348,7 +337,7 @@ export function useAutomationSelectionKeyboard({
|
|
|
348
337
|
const sel = state.automationSelection;
|
|
349
338
|
if (!sel) return;
|
|
350
339
|
|
|
351
|
-
if (e
|
|
340
|
+
if (matchesKey(e, "cancel")) {
|
|
352
341
|
state.clearAutomationSelection();
|
|
353
342
|
return;
|
|
354
343
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useCallback } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { matchesKey } from "../player/components/studioShortcuts";
|
|
3
3
|
import { isTypingTarget } from "../utils/typingTarget";
|
|
4
4
|
|
|
5
5
|
interface KeyframeKeyboardOptions {
|
|
@@ -12,8 +12,7 @@ export function useKeyframeKeyboard({ enabled, onAddKeyframe }: KeyframeKeyboard
|
|
|
12
12
|
(e: KeyboardEvent) => {
|
|
13
13
|
if (!enabled || !onAddKeyframe) return;
|
|
14
14
|
if (isTypingTarget(document.activeElement)) return;
|
|
15
|
-
if (e
|
|
16
|
-
if (e.key.toLowerCase() !== getStudioKey("addKeyframe")) return;
|
|
15
|
+
if (!matchesKey(e, "addKeyframe")) return;
|
|
17
16
|
// K is also playback's stop key: claiming it here keeps playback from also pausing.
|
|
18
17
|
e.preventDefault();
|
|
19
18
|
e.stopImmediatePropagation();
|
|
@@ -2,6 +2,7 @@ import { buildProjectApiPath } from "../utils/projectRouting";
|
|
|
2
2
|
// Timeline clip deletion: the marquee/multi path and the single-clip wrapper
|
|
3
3
|
// the context menu uses. Extracted verbatim from useTimelineEditing.ts to keep
|
|
4
4
|
// it under the studio 600-line cap, following useTimelineAssetDropOps.
|
|
5
|
+
import { keyHint } from "../player/components/studioShortcuts";
|
|
5
6
|
import { useCallback, useRef, type MutableRefObject, type RefObject } from "react";
|
|
6
7
|
import type { TimelineElement } from "../player";
|
|
7
8
|
import { usePlayerStore } from "../player";
|
|
@@ -216,7 +217,7 @@ export function useTimelineDeleteOps({
|
|
|
216
217
|
if (rippleChanges && !rippleFailed && !rippleNoticeShownRef.current) {
|
|
217
218
|
rippleNoticeShownRef.current = true;
|
|
218
219
|
showToast(
|
|
219
|
-
|
|
220
|
+
`Ripple closed the gap on the main track. Undo (${keyHint("undo")}) restores it, or turn off ` +
|
|
220
221
|
"Ripple in the timeline toolbar.",
|
|
221
222
|
"info",
|
|
222
223
|
);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { memo, useSyncExternalStore } from "react";
|
|
2
|
+
import { matchesKey } from "./studioShortcuts";
|
|
2
3
|
import {
|
|
3
4
|
deleteBeatAtCompositionTime,
|
|
4
5
|
moveBeatCompositionTime,
|
|
@@ -184,7 +185,7 @@ function handleBeatDragPointerCancel(event: PointerEvent): void {
|
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
function handleBeatDragKeyDown(event: KeyboardEvent): void {
|
|
187
|
-
if (event
|
|
188
|
+
if (!matchesKey(event, "cancel") || !beatDragActor) return;
|
|
188
189
|
event.preventDefault();
|
|
189
190
|
cancelBeatDrag();
|
|
190
191
|
}
|
|
@@ -215,7 +215,7 @@ export const ClipContextMenu = memo(function ClipContextMenu({
|
|
|
215
215
|
}}
|
|
216
216
|
>
|
|
217
217
|
<span>{selectionSize > 1 ? `Copy ${selectionSize} clips` : "Copy"}</span>
|
|
218
|
-
<span className="text-neutral-500 text-[10px] ml-3"
|
|
218
|
+
<span className="text-neutral-500 text-[10px] ml-3">{keyHint("copy", keys)}</span>
|
|
219
219
|
</button>
|
|
220
220
|
)}
|
|
221
221
|
{onPaste && (
|
|
@@ -231,7 +231,7 @@ export const ClipContextMenu = memo(function ClipContextMenu({
|
|
|
231
231
|
}}
|
|
232
232
|
>
|
|
233
233
|
<span>Paste</span>
|
|
234
|
-
<span className="text-neutral-500 text-[10px] ml-3"
|
|
234
|
+
<span className="text-neutral-500 text-[10px] ml-3">{keyHint("paste", keys)}</span>
|
|
235
235
|
</button>
|
|
236
236
|
)}
|
|
237
237
|
{onDuplicate && (
|
|
@@ -245,7 +245,7 @@ export const ClipContextMenu = memo(function ClipContextMenu({
|
|
|
245
245
|
}}
|
|
246
246
|
>
|
|
247
247
|
<span>{selectionSize > 1 ? `Duplicate ${selectionSize} clips` : "Duplicate"}</span>
|
|
248
|
-
<span className="text-neutral-500 text-[10px] ml-3"
|
|
248
|
+
<span className="text-neutral-500 text-[10px] ml-3">{keyHint("duplicate", keys)}</span>
|
|
249
249
|
</button>
|
|
250
250
|
)}
|
|
251
251
|
</div>
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type KeyboardEvent,
|
|
10
10
|
type PointerEvent,
|
|
11
11
|
} from "react";
|
|
12
|
+
import { matchesKey } from "./studioShortcuts";
|
|
12
13
|
import {
|
|
13
14
|
HF_AUDIO_FADE_IN_ATTR,
|
|
14
15
|
HF_AUDIO_FADE_OUT_ATTR,
|
|
@@ -329,7 +330,7 @@ export function TimelineClipFades({
|
|
|
329
330
|
if (dragging === null) return;
|
|
330
331
|
const cancelOnWindowEscape = (e: globalThis.KeyboardEvent) => {
|
|
331
332
|
const g = gesture.current;
|
|
332
|
-
if (e
|
|
333
|
+
if (!matchesKey(e, "cancel") || !g) return;
|
|
333
334
|
e.preventDefault();
|
|
334
335
|
e.stopPropagation();
|
|
335
336
|
gesture.current = null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { usePlayerStore, type TimelineElement } from "../store/playerStore";
|
|
2
|
+
import { keyHint } from "./studioShortcuts";
|
|
2
3
|
import { useTimelineEditContextOptional } from "../../contexts/TimelineEditContext";
|
|
3
4
|
import type { TimelineLinkEdit } from "./timelineCallbacks";
|
|
4
5
|
import { linkedMembersOf } from "./audioClipLink";
|
|
@@ -61,7 +62,7 @@ function linkItem(
|
|
|
61
62
|
const suffix = partnerSuffix(element, linkPair);
|
|
62
63
|
return {
|
|
63
64
|
label: `Link${suffix && ` to${suffix}`}`,
|
|
64
|
-
...(selectedPair ? { shortcut: "
|
|
65
|
+
...(selectedPair ? { shortcut: keyHint("linkToggle") } : {}),
|
|
65
66
|
run: () => onLinkEdit({ kind: "link", elements: linkPair }),
|
|
66
67
|
};
|
|
67
68
|
}
|
|
@@ -82,7 +83,7 @@ export function resolveLinkMenuItems(input: {
|
|
|
82
83
|
if (canDetachAudio(element)) {
|
|
83
84
|
items.push({
|
|
84
85
|
label: "Detach audio",
|
|
85
|
-
shortcut: "
|
|
86
|
+
shortcut: keyHint("detachAudio"),
|
|
86
87
|
run: () => onLinkEdit({ kind: "detach", element }),
|
|
87
88
|
});
|
|
88
89
|
}
|
|
@@ -90,7 +91,7 @@ export function resolveLinkMenuItems(input: {
|
|
|
90
91
|
if (linked) {
|
|
91
92
|
items.push({
|
|
92
93
|
label: `Unlink${partnerSuffix(element, members) && ` from${partnerSuffix(element, members)}`}`,
|
|
93
|
-
shortcut: "
|
|
94
|
+
shortcut: keyHint("linkToggle"),
|
|
94
95
|
run: () => onLinkEdit({ kind: "unlink", elements: members }),
|
|
95
96
|
});
|
|
96
97
|
} else {
|
|
@@ -108,7 +109,7 @@ export function resolveLinkMenuItems(input: {
|
|
|
108
109
|
if (linked && onDeleteElementOnly) {
|
|
109
110
|
items.push({
|
|
110
111
|
label: "Delete this clip only",
|
|
111
|
-
shortcut: "
|
|
112
|
+
shortcut: keyHint("deleteLinked"),
|
|
112
113
|
destructive: true,
|
|
113
114
|
run: () => onDeleteElementOnly(element),
|
|
114
115
|
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { formatCombo, matchCombo, parseCombo } from "./studioCombo";
|
|
4
|
+
import { getStudioKey, keyHint, matchesKey, setStudioKeys } from "./studioShortcuts";
|
|
5
|
+
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
setStudioKeys(null);
|
|
8
|
+
vi.restoreAllMocks();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const press = (init: KeyboardEventInit) => new KeyboardEvent("keydown", init);
|
|
12
|
+
const matches = (text: string, init: KeyboardEventInit) =>
|
|
13
|
+
matchCombo(press(init), parseCombo(text)!);
|
|
14
|
+
|
|
15
|
+
describe("combo model", () => {
|
|
16
|
+
it("parses characters, named keys and modifiers", () => {
|
|
17
|
+
expect(parseCombo("B")).toMatchObject({ key: "b", named: false });
|
|
18
|
+
expect(parseCombo("Space")).toMatchObject({ key: "Space", named: true });
|
|
19
|
+
expect(parseCombo("mod+shift+z")).toMatchObject({ mod: true, shift: true, key: "z" });
|
|
20
|
+
expect(parseCombo("cmd++")).toMatchObject({ meta: true, key: "+" });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("refuses what cannot be matched: modifier-only, unknown, empty, and Ctrl+Alt (AltGr on Windows)", () => {
|
|
24
|
+
for (const bad of [
|
|
25
|
+
"ctrl",
|
|
26
|
+
"shift+",
|
|
27
|
+
"",
|
|
28
|
+
"mod+ab",
|
|
29
|
+
"hyper+x",
|
|
30
|
+
"ctrl+alt+x",
|
|
31
|
+
"mod+alt+x",
|
|
32
|
+
"Spacebar",
|
|
33
|
+
]) {
|
|
34
|
+
expect(parseCombo(bad), bad).toBeNull();
|
|
35
|
+
}
|
|
36
|
+
expect(parseCombo("cmd+alt+x")).not.toBeNull();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("mod is Cmd or Ctrl; cmd and ctrl are exact; extra modifiers never match", () => {
|
|
40
|
+
expect(matches("mod+c", { key: "c", metaKey: true })).toBe(true);
|
|
41
|
+
expect(matches("mod+c", { key: "c", ctrlKey: true })).toBe(true);
|
|
42
|
+
expect(matches("mod+c", { key: "c" })).toBe(false);
|
|
43
|
+
expect(matches("mod+c", { key: "c", metaKey: true, shiftKey: true })).toBe(false);
|
|
44
|
+
expect(matches("cmd+c", { key: "c", ctrlKey: true })).toBe(false);
|
|
45
|
+
expect(matches("c", { key: "c", metaKey: true })).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("characters match e.key (so layouts follow the typed letter), named keys match e.code", () => {
|
|
49
|
+
expect(matches("a", { key: "a", code: "KeyQ" })).toBe(true);
|
|
50
|
+
expect(matches("a", { key: "q", code: "KeyA" })).toBe(false);
|
|
51
|
+
expect(matches("Space", { key: " ", code: "Space" })).toBe(true);
|
|
52
|
+
expect(
|
|
53
|
+
matches("shift+ArrowLeft", { key: "ArrowLeft", code: "ArrowLeft", shiftKey: true }),
|
|
54
|
+
).toBe(true);
|
|
55
|
+
expect(matches("alt+shift+d", { key: "∂", code: "KeyD", altKey: true, shiftKey: true })).toBe(
|
|
56
|
+
true,
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("formats like the shortcut lists do", () => {
|
|
61
|
+
expect(formatCombo(parseCombo("mod+shift+z")!)).toBe("⌘⇧Z");
|
|
62
|
+
expect(formatCombo(parseCombo("alt+shift+d")!)).toBe("⌥⇧D");
|
|
63
|
+
expect(formatCombo(parseCombo("ArrowLeft")!)).toBe("←");
|
|
64
|
+
expect(formatCombo(parseCombo("[")!)).toBe("[");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("resolver with combos", () => {
|
|
69
|
+
it("accepts a combo for an action that today takes a single key, and the list follows", () => {
|
|
70
|
+
setStudioKeys({ fullscreen: "mod+shift+f" });
|
|
71
|
+
expect(getStudioKey("fullscreen")).toBe("mod+shift+f");
|
|
72
|
+
expect(keyHint("fullscreen")).toBe("⌘⇧F");
|
|
73
|
+
expect(matchesKey(press({ key: "F", metaKey: true, shiftKey: true }), "fullscreen")).toBe(true);
|
|
74
|
+
expect(matchesKey(press({ key: "f" }), "fullscreen")).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("keeps a single character working and canonical", () => {
|
|
78
|
+
setStudioKeys({ mute: "X" });
|
|
79
|
+
expect(getStudioKey("mute")).toBe("x");
|
|
80
|
+
expect(matchesKey(press({ key: "x" }), "mute")).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("refuses a map with an AltGr combo or two actions on one combo, keeping every default", () => {
|
|
84
|
+
vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
85
|
+
setStudioKeys({ mute: "ctrl+alt+m" });
|
|
86
|
+
expect(getStudioKey("mute")).toBe("m");
|
|
87
|
+
setStudioKeys({ mute: "mod+k", record: "cmd+k" });
|
|
88
|
+
expect(getStudioKey("mute")).toBe("m");
|
|
89
|
+
expect(getStudioKey("record")).toBe("r");
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("combos with symbol keys", () => {
|
|
94
|
+
it("matches a symbol whatever Shift it needs, and refuses shift+symbol", () => {
|
|
95
|
+
expect(matches("?", { key: "?", shiftKey: true })).toBe(true);
|
|
96
|
+
expect(matches("mod++", { key: "+", metaKey: true, shiftKey: true })).toBe(true);
|
|
97
|
+
expect(parseCombo("shift+1")).toBeNull();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export interface Combo {
|
|
2
|
+
mod: boolean;
|
|
3
|
+
meta: boolean;
|
|
4
|
+
ctrl: boolean;
|
|
5
|
+
shift: boolean;
|
|
6
|
+
alt: boolean;
|
|
7
|
+
key: string;
|
|
8
|
+
named: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const NAMED = new Set([
|
|
12
|
+
"Space",
|
|
13
|
+
"ArrowLeft",
|
|
14
|
+
"ArrowRight",
|
|
15
|
+
"ArrowUp",
|
|
16
|
+
"ArrowDown",
|
|
17
|
+
"Home",
|
|
18
|
+
"End",
|
|
19
|
+
"PageUp",
|
|
20
|
+
"PageDown",
|
|
21
|
+
"Delete",
|
|
22
|
+
"Backspace",
|
|
23
|
+
"Escape",
|
|
24
|
+
"Enter",
|
|
25
|
+
"Tab",
|
|
26
|
+
]);
|
|
27
|
+
const SYMBOL: Record<string, string> = {
|
|
28
|
+
ArrowLeft: "←",
|
|
29
|
+
ArrowRight: "→",
|
|
30
|
+
ArrowUp: "↑",
|
|
31
|
+
ArrowDown: "↓",
|
|
32
|
+
Delete: "Del",
|
|
33
|
+
Backspace: "⌫",
|
|
34
|
+
Escape: "Esc",
|
|
35
|
+
};
|
|
36
|
+
const MODIFIERS = new Set(["mod", "cmd", "ctrl", "shift", "alt"]);
|
|
37
|
+
|
|
38
|
+
/** "mod+shift+z", "Space", "b": mod is Cmd or Ctrl; Ctrl+Alt is refused because Windows sends AltGr as Ctrl+Alt. */
|
|
39
|
+
export function parseCombo(text: string): Combo | null {
|
|
40
|
+
const split = text.length > 1 ? text.slice(0, -1).lastIndexOf("+") : -1;
|
|
41
|
+
const tokens =
|
|
42
|
+
split < 0
|
|
43
|
+
? []
|
|
44
|
+
: text
|
|
45
|
+
.slice(0, split)
|
|
46
|
+
.split("+")
|
|
47
|
+
.map((t) => t.toLowerCase());
|
|
48
|
+
const key = text.slice(split + 1);
|
|
49
|
+
const named = NAMED.has(key);
|
|
50
|
+
const symbol = !named && !/^[A-Za-z]$/.test(key);
|
|
51
|
+
if (tokens.some((t) => !MODIFIERS.has(t)) || (!named && [...key].length !== 1)) return null;
|
|
52
|
+
if (symbol && tokens.includes("shift")) return null;
|
|
53
|
+
const combo = {
|
|
54
|
+
mod: tokens.includes("mod"),
|
|
55
|
+
meta: tokens.includes("cmd"),
|
|
56
|
+
ctrl: tokens.includes("ctrl"),
|
|
57
|
+
shift: tokens.includes("shift"),
|
|
58
|
+
alt: tokens.includes("alt"),
|
|
59
|
+
key: named ? key : key.toLowerCase(),
|
|
60
|
+
named,
|
|
61
|
+
};
|
|
62
|
+
return combo.alt && (combo.ctrl || combo.mod) ? null : combo;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The one string a combo is stored and compared as. */
|
|
66
|
+
export function comboText(c: Combo): string {
|
|
67
|
+
const mods = [
|
|
68
|
+
c.mod && "mod",
|
|
69
|
+
c.meta && "cmd",
|
|
70
|
+
c.ctrl && "ctrl",
|
|
71
|
+
c.alt && "alt",
|
|
72
|
+
c.shift && "shift",
|
|
73
|
+
];
|
|
74
|
+
return [...mods.filter(Boolean), c.key].join("+");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const namedMatches = (e: ComboEvent, name: string) =>
|
|
78
|
+
e.code === name || e.key === (name === "Space" ? " " : name);
|
|
79
|
+
|
|
80
|
+
function charMatches(e: ComboEvent, c: Combo): boolean {
|
|
81
|
+
if (e.key.toLowerCase() === c.key) return true;
|
|
82
|
+
// Option rewrites e.key on macOS (Option+D is "∂"), so fall back to the physical key.
|
|
83
|
+
const code = /^[0-9]$/.test(c.key) ? `Digit${c.key}` : `Key${c.key.toUpperCase()}`;
|
|
84
|
+
return e.altKey && /^[a-z0-9]$/.test(c.key) && e.code === code;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type ComboEvent = Pick<
|
|
88
|
+
KeyboardEvent,
|
|
89
|
+
"key" | "altKey" | "ctrlKey" | "metaKey" | "shiftKey"
|
|
90
|
+
> & {
|
|
91
|
+
code?: string;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export function matchCombo(e: ComboEvent, c: Combo): boolean {
|
|
95
|
+
const symbol = !c.named && !/^[a-z]$/.test(c.key);
|
|
96
|
+
if ((!symbol && !!e.shiftKey !== c.shift) || !!e.altKey !== c.alt) return false;
|
|
97
|
+
const modsOk = c.mod ? e.metaKey || e.ctrlKey : !!e.metaKey === c.meta && !!e.ctrlKey === c.ctrl;
|
|
98
|
+
return modsOk && (c.named ? namedMatches(e, c.key) : charMatches(e, c));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function formatCombo(c: Combo): string {
|
|
102
|
+
const mods = `${c.ctrl ? "⌃" : ""}${c.alt ? "⌥" : ""}${c.mod || c.meta ? "⌘" : ""}${c.shift ? "⇧" : ""}`;
|
|
103
|
+
return mods + (SYMBOL[c.key] ?? (c.named ? c.key : c.key.toUpperCase()));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Two combos clash when one press could satisfy both; Cmd and Ctrl both count as mod. */
|
|
107
|
+
export const comboClashKey = (c: Combo) =>
|
|
108
|
+
[c.mod || c.meta || c.ctrl, c.alt, c.shift, c.key].join("|");
|