@hyperframes/studio 0.8.229 → 0.8.230
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-CtwXT8nW.js → hyperframes-player-Dv5Ew1Dr.js} +1 -1
- package/dist/assets/{index-CrRO-B3w.js → index-BvqtI0ko.js} +160 -160
- package/dist/assets/{index-CNO8BPjF.js → index-hiL49K7x.js} +1 -1
- package/dist/index.d.ts +33 -2
- package/dist/index.html +1 -1
- package/dist/index.js +2140 -1991
- package/package.json +8 -8
- package/src/components/TimelineToolPicker.tsx +6 -4
- package/src/components/TimelineToolbar.tsx +22 -17
- package/src/components/editor/GestureRecordControl.tsx +8 -3
- package/src/components/editor/PropertyPanelFlatFooter.tsx +3 -1
- package/src/components/editor/SnapToolbar.tsx +11 -5
- package/src/hooks/appHotkeysDispatch.ts +25 -26
- package/src/hooks/useAppHotkeys.test.ts +58 -0
- package/src/hooks/useKeyframeKeyboard.ts +2 -2
- package/src/index.ts +9 -1
- package/src/player/components/ClipContextMenu.tsx +6 -3
- package/src/player/components/PlayerControls.tsx +3 -2
- package/src/player/components/ShortcutsPanel.tsx +3 -2
- package/src/player/components/studioShortcuts.test.tsx +109 -0
- package/src/player/components/studioShortcuts.ts +187 -94
- package/src/player/hooks/usePlaybackKeyboard.test.ts +78 -1
- package/src/player/hooks/usePlaybackKeyboard.ts +36 -40
- package/src/player/hooks/useShadowPreviewReload.ts +11 -4
- package/src/player/hooks/useShadowReloadRetry.ts +68 -0
- package/src/player/hooks/useTimelinePlayer.shadowRetry.test.ts +85 -0
- package/src/player/lib/playbackShortcuts.ts +12 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import React, { act } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_SHORTCUT_SECTIONS,
|
|
7
|
+
DEFAULT_STUDIO_KEYS,
|
|
8
|
+
getShortcutSections,
|
|
9
|
+
getStudioKey,
|
|
10
|
+
setStudioKeys,
|
|
11
|
+
useStudioKeys,
|
|
12
|
+
} from "./studioShortcuts";
|
|
13
|
+
|
|
14
|
+
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
setStudioKeys(null);
|
|
18
|
+
document.body.innerHTML = "";
|
|
19
|
+
vi.restoreAllMocks();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const hintFor = (label: string) =>
|
|
23
|
+
getShortcutSections()
|
|
24
|
+
.flatMap((s) => s.hints)
|
|
25
|
+
.find((h) => h.label === label)?.key;
|
|
26
|
+
|
|
27
|
+
describe("studio key resolver", () => {
|
|
28
|
+
it("answers today's keys when no host overrides anything", () => {
|
|
29
|
+
expect(DEFAULT_STUDIO_KEYS).toMatchObject({
|
|
30
|
+
mute: "m",
|
|
31
|
+
pause: "k",
|
|
32
|
+
shuttleBack: "j",
|
|
33
|
+
shuttleForward: "l",
|
|
34
|
+
inPoint: "i",
|
|
35
|
+
outPoint: "o",
|
|
36
|
+
seekToIn: "a",
|
|
37
|
+
seekToOut: "e",
|
|
38
|
+
fullscreen: "f",
|
|
39
|
+
split: "s",
|
|
40
|
+
record: "r",
|
|
41
|
+
addKeyframe: "k",
|
|
42
|
+
audioGain: "g",
|
|
43
|
+
zoomSelection: "z",
|
|
44
|
+
selectTool: "v",
|
|
45
|
+
razorTool: "b",
|
|
46
|
+
selectLeftward: "[",
|
|
47
|
+
selectRightward: "]",
|
|
48
|
+
exitRazor: "a",
|
|
49
|
+
snap: "s",
|
|
50
|
+
grid: "g",
|
|
51
|
+
timelineSnap: "n",
|
|
52
|
+
});
|
|
53
|
+
expect(getShortcutSections()).toEqual(DEFAULT_SHORTCUT_SECTIONS);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("normalises an override to lower case and leaves the other actions alone", () => {
|
|
57
|
+
setStudioKeys({ mute: "X" });
|
|
58
|
+
expect(getStudioKey("mute")).toBe("x");
|
|
59
|
+
expect(getStudioKey("fullscreen")).toBe("f");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("lists the remapped key in the shortcut list", () => {
|
|
63
|
+
setStudioKeys({ mute: "x", seekToIn: "u" });
|
|
64
|
+
expect(hintFor("Toggle mute")).toBe("X");
|
|
65
|
+
expect(hintFor("Jump to in-point")).toBe("U");
|
|
66
|
+
expect(hintFor("Toggle loop")).toBe("⇧L");
|
|
67
|
+
setStudioKeys({ shuttleForward: "y" });
|
|
68
|
+
expect(hintFor("Play forward")).toBe("Y");
|
|
69
|
+
expect(hintFor("Toggle loop")).toBe("⇧Y");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("refuses a map that binds two actions to one key and keeps every default", () => {
|
|
73
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
74
|
+
setStudioKeys({ mute: "x", razorTool: "x" });
|
|
75
|
+
expect(getStudioKey("mute")).toBe("m");
|
|
76
|
+
expect(getStudioKey("razorTool")).toBe("b");
|
|
77
|
+
setStudioKeys({ mute: "x", razorTool: "x" });
|
|
78
|
+
expect(warn).toHaveBeenCalledTimes(2);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("refuses a key that is not one character", () => {
|
|
82
|
+
vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
83
|
+
setStudioKeys({ razorTool: "y", mute: "ctrl" });
|
|
84
|
+
expect(getStudioKey("mute")).toBe("m");
|
|
85
|
+
expect(getStudioKey("razorTool")).toBe("b");
|
|
86
|
+
setStudioKeys({ razorTool: "y", toString: "z" } as never);
|
|
87
|
+
expect(getStudioKey("razorTool")).toBe("b");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("still lets the keys Studio already shares (K stop/keyframe, S split/snap) share", () => {
|
|
91
|
+
setStudioKeys({ mute: "x" });
|
|
92
|
+
expect(getStudioKey("pause")).toBe(getStudioKey("addKeyframe"));
|
|
93
|
+
expect(getStudioKey("mute")).toBe("x");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("re-renders a component using the hook when the host swaps the map", () => {
|
|
97
|
+
function Probe() {
|
|
98
|
+
return <span data-probe>{useStudioKeys().razorTool}</span>;
|
|
99
|
+
}
|
|
100
|
+
const host = document.createElement("div");
|
|
101
|
+
document.body.append(host);
|
|
102
|
+
const root = createRoot(host);
|
|
103
|
+
act(() => root.render(<Probe />));
|
|
104
|
+
expect(host.textContent).toBe("b");
|
|
105
|
+
act(() => setStudioKeys({ razorTool: "y" }));
|
|
106
|
+
expect(host.textContent).toBe("y");
|
|
107
|
+
act(() => root.unmount());
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -1,12 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
|
|
3
|
+
/** Every single-character bare key Studio answers, by action. */
|
|
4
|
+
export const DEFAULT_STUDIO_KEYS = {
|
|
3
5
|
fullscreen: "f",
|
|
4
6
|
split: "s",
|
|
5
7
|
record: "r",
|
|
6
8
|
addKeyframe: "k",
|
|
7
9
|
audioGain: "g",
|
|
8
10
|
zoomSelection: "z",
|
|
9
|
-
|
|
11
|
+
mute: "m",
|
|
12
|
+
pause: "k",
|
|
13
|
+
shuttleBack: "j",
|
|
14
|
+
shuttleForward: "l",
|
|
15
|
+
inPoint: "i",
|
|
16
|
+
outPoint: "o",
|
|
17
|
+
seekToIn: "a",
|
|
18
|
+
seekToOut: "e",
|
|
19
|
+
selectTool: "v",
|
|
20
|
+
razorTool: "b",
|
|
21
|
+
selectLeftward: "[",
|
|
22
|
+
selectRightward: "]",
|
|
23
|
+
exitRazor: "a",
|
|
24
|
+
snap: "s",
|
|
25
|
+
grid: "g",
|
|
26
|
+
timelineSnap: "n",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type StudioKeyAction = keyof typeof DEFAULT_STUDIO_KEYS;
|
|
30
|
+
export type StudioKeys = Readonly<Record<StudioKeyAction, string>>;
|
|
31
|
+
|
|
32
|
+
const SHARED_BY_DESIGN: ReadonlyArray<readonly [StudioKeyAction, StudioKeyAction]> = [
|
|
33
|
+
["pause", "addKeyframe"],
|
|
34
|
+
["seekToIn", "exitRazor"],
|
|
35
|
+
["split", "snap"],
|
|
36
|
+
["audioGain", "grid"],
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
let current: StudioKeys = DEFAULT_STUDIO_KEYS;
|
|
40
|
+
const listeners = new Set<() => void>();
|
|
41
|
+
|
|
42
|
+
const sharedByDesign = (a: StudioKeyAction, b: StudioKeyAction) =>
|
|
43
|
+
SHARED_BY_DESIGN.some(([x, y]) => (x === a && y === b) || (x === b && y === a));
|
|
44
|
+
|
|
45
|
+
function findClash(keys: StudioKeys): string | null {
|
|
46
|
+
const actions = Object.keys(keys) as StudioKeyAction[];
|
|
47
|
+
for (const [i, a] of actions.entries()) {
|
|
48
|
+
for (const b of actions.slice(i + 1)) {
|
|
49
|
+
if (keys[a] === keys[b] && !sharedByDesign(a, b)) return `${a} and ${b} both on "${keys[a]}"`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function resolve(overrides: Partial<Record<StudioKeyAction, string>>): StudioKeys {
|
|
56
|
+
const next: Record<string, string> = { ...DEFAULT_STUDIO_KEYS };
|
|
57
|
+
for (const [action, key] of Object.entries(overrides)) {
|
|
58
|
+
if (
|
|
59
|
+
!Object.hasOwn(DEFAULT_STUDIO_KEYS, action) ||
|
|
60
|
+
typeof key !== "string" ||
|
|
61
|
+
[...key].length !== 1
|
|
62
|
+
) {
|
|
63
|
+
console.warn(
|
|
64
|
+
`Studio keys: using defaults, "${action}" is not a known action with one character`,
|
|
65
|
+
);
|
|
66
|
+
return DEFAULT_STUDIO_KEYS;
|
|
67
|
+
}
|
|
68
|
+
next[action] = key.toLowerCase();
|
|
69
|
+
}
|
|
70
|
+
const clash = findClash(next as StudioKeys);
|
|
71
|
+
if (!clash) return next as StudioKeys;
|
|
72
|
+
console.warn(`Studio keys: using defaults, ${clash}`);
|
|
73
|
+
return DEFAULT_STUDIO_KEYS;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Replaces the host key map; a bad map is refused whole. null restores the defaults. */
|
|
77
|
+
export function setStudioKeys(overrides: Partial<Record<StudioKeyAction, string>> | null) {
|
|
78
|
+
current = overrides ? resolve(overrides) : DEFAULT_STUDIO_KEYS;
|
|
79
|
+
for (const listener of listeners) listener();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const getStudioKeys = (): StudioKeys => current;
|
|
83
|
+
export const getStudioKey = (action: StudioKeyAction): string => current[action];
|
|
84
|
+
|
|
85
|
+
function subscribe(listener: () => void) {
|
|
86
|
+
listeners.add(listener);
|
|
87
|
+
return () => listeners.delete(listener);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const useStudioKeys = (): StudioKeys => useSyncExternalStore(subscribe, getStudioKeys);
|
|
91
|
+
|
|
92
|
+
export function useShortcutSections(host?: readonly ShortcutSection[]): readonly ShortcutSection[] {
|
|
93
|
+
const keys = useStudioKeys();
|
|
94
|
+
return host ?? buildShortcutSections(keys);
|
|
95
|
+
}
|
|
10
96
|
|
|
11
97
|
export interface ShortcutHint {
|
|
12
98
|
key: string;
|
|
@@ -20,94 +106,101 @@ export interface ShortcutSection {
|
|
|
20
106
|
|
|
21
107
|
const hintKey = (key: string) => key.toUpperCase();
|
|
22
108
|
|
|
23
|
-
export const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
export const keyHint = (action: StudioKeyAction, keys: StudioKeys = current) =>
|
|
110
|
+
hintKey(keys[action]);
|
|
111
|
+
|
|
112
|
+
export function buildShortcutSections(keys: StudioKeys): readonly ShortcutSection[] {
|
|
113
|
+
const k = (action: StudioKeyAction) => keyHint(action, keys);
|
|
114
|
+
return [
|
|
115
|
+
{
|
|
116
|
+
title: "Playback",
|
|
117
|
+
hints: [
|
|
118
|
+
{ key: "Space", label: "Play / Pause" },
|
|
119
|
+
{ key: k("shuttleBack"), label: "Play backward" },
|
|
120
|
+
{ key: k("pause"), label: "Stop" },
|
|
121
|
+
{ key: k("shuttleForward"), label: "Play forward" },
|
|
122
|
+
{ key: k("mute"), label: "Toggle mute" },
|
|
123
|
+
{ key: `⇧${k("shuttleForward")}`, label: "Toggle loop" },
|
|
124
|
+
{ key: "←/→", label: "Step 1 frame" },
|
|
125
|
+
{ key: "⇧←/⇧→", label: "Step 10 frames" },
|
|
126
|
+
{ key: k("fullscreen"), label: "Toggle fullscreen" },
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
title: "Keyframes (when an element is selected)",
|
|
131
|
+
hints: [
|
|
132
|
+
{ key: k("addKeyframe"), label: "Add / remove keyframe at playhead" },
|
|
133
|
+
{ key: "Del", label: "Delete selected keyframe" },
|
|
134
|
+
{ key: k("record"), label: "Record gesture" },
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
title: "Editing",
|
|
139
|
+
hints: [
|
|
140
|
+
{ key: "⌘Z", label: "Undo" },
|
|
141
|
+
{ key: "⌘⇧Z", label: "Redo" },
|
|
142
|
+
{ key: "⌘C", label: "Copy element" },
|
|
143
|
+
{ key: "⌘V", label: "Paste element" },
|
|
144
|
+
{ key: "⌘X", label: "Cut element" },
|
|
145
|
+
{ key: k("split"), label: "Split clip at playhead" },
|
|
146
|
+
{ key: k("zoomSelection"), label: "Zoom timeline to selected clips" },
|
|
147
|
+
{ key: k("audioGain"), label: "Audio Gain for clips with sound" },
|
|
148
|
+
{ key: "⇧Click", label: "Razor tool: split all tracks" },
|
|
149
|
+
{ key: k("selectLeftward"), label: "Select clips starting before the playhead" },
|
|
150
|
+
{ key: k("selectRightward"), label: "Select clips running at or after the playhead" },
|
|
151
|
+
{ key: "⌘G", label: "Group elements" },
|
|
152
|
+
{ key: "⌘⇧G", label: "Ungroup" },
|
|
153
|
+
{ key: "Del", label: "Delete selected element (no keyframe selected)" },
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
title: "Gesture recording modifiers",
|
|
158
|
+
hints: [
|
|
159
|
+
{ key: "Drag", label: "Record x / y position" },
|
|
160
|
+
{ key: "Scroll", label: "Record z depth" },
|
|
161
|
+
{ key: "⇧ Drag", label: "Record rotationX / rotationY" },
|
|
162
|
+
{ key: "⌥ Drag", label: "Record rotation" },
|
|
163
|
+
{ key: "⌘ Drag↕", label: "Record opacity" },
|
|
164
|
+
{ key: "⌘ Scroll", label: "Record scale" },
|
|
165
|
+
],
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
title: "Canvas",
|
|
169
|
+
hints: [
|
|
170
|
+
{ key: "Drag", label: "Move element / add keyframe" },
|
|
171
|
+
{ key: "⌥ Drag", label: "Move entire animation path" },
|
|
172
|
+
{ key: "⇧ Drag", label: "Uniform resize" },
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
title: "Crop",
|
|
177
|
+
hints: [
|
|
178
|
+
{ key: "Drag edge", label: "Crop a side" },
|
|
179
|
+
{ key: "Drag center", label: "Reposition the crop" },
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
title: "Panels",
|
|
184
|
+
hints: [
|
|
185
|
+
{ key: "⌘1", label: "Compositions tab" },
|
|
186
|
+
{ key: "⌘2", label: "Assets tab" },
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
title: "Work area",
|
|
191
|
+
hints: [
|
|
192
|
+
{ key: k("inPoint"), label: "Set in-point" },
|
|
193
|
+
{ key: `⇧${k("inPoint")}`, label: "Clear in-point" },
|
|
194
|
+
{ key: k("outPoint"), label: "Set out-point" },
|
|
195
|
+
{ key: `⇧${k("outPoint")}`, label: "Clear out-point" },
|
|
196
|
+
{ key: k("seekToIn"), label: "Jump to in-point" },
|
|
197
|
+
{ key: k("seekToOut"), label: "Jump to out-point" },
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export const getShortcutSections = () => buildShortcutSections(current);
|
|
204
|
+
|
|
205
|
+
export const DEFAULT_SHORTCUT_SECTIONS: readonly ShortcutSection[] =
|
|
206
|
+
buildShortcutSections(DEFAULT_STUDIO_KEYS);
|
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
|
|
4
4
|
import React, { act, useEffect } from "react";
|
|
5
5
|
import { createRoot } from "react-dom/client";
|
|
6
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
7
7
|
import { usePlaybackKeyboard } from "./usePlaybackKeyboard";
|
|
8
8
|
import { usePlayerStore } from "../store/playerStore";
|
|
9
|
+
import { setStudioKeys } from "../components/studioShortcuts";
|
|
9
10
|
import { useLinkedClipPreferences } from "../../utils/linkedClipPreferences";
|
|
10
11
|
|
|
11
12
|
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
12
13
|
|
|
13
14
|
afterEach(() => {
|
|
15
|
+
setStudioKeys(null);
|
|
14
16
|
document.body.innerHTML = "";
|
|
15
17
|
usePlayerStore.getState().reset();
|
|
16
18
|
useLinkedClipPreferences.getState().setCompositionFps(30);
|
|
@@ -323,3 +325,78 @@ describe("usePlaybackKeyboard — frame step", () => {
|
|
|
323
325
|
expect(spies.seek).toHaveBeenCalledWith((frame + 1) / fps);
|
|
324
326
|
});
|
|
325
327
|
});
|
|
328
|
+
|
|
329
|
+
describe("usePlaybackKeyboard — keys the host can remap", () => {
|
|
330
|
+
beforeEach(() => usePlayerStore.setState({ audioMuted: false, loopEnabled: false }));
|
|
331
|
+
|
|
332
|
+
const press = (dispatch: HookHandle["dispatch"], key: string, shiftKey = false) =>
|
|
333
|
+
act(() => {
|
|
334
|
+
dispatch(keydown({ code: `Key${key.toUpperCase()}`, key, shiftKey }));
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("answers every default key", () => {
|
|
338
|
+
const { dispatch, release, spies } = setupHook();
|
|
339
|
+
press(dispatch, "m");
|
|
340
|
+
expect(usePlayerStore.getState().audioMuted).toBe(true);
|
|
341
|
+
press(dispatch, "l", true);
|
|
342
|
+
expect(usePlayerStore.getState().loopEnabled).toBe(true);
|
|
343
|
+
press(dispatch, "k");
|
|
344
|
+
expect(spies.pause).toHaveBeenCalledTimes(1);
|
|
345
|
+
act(() => release(keyup({ code: "KeyK", key: "k" })));
|
|
346
|
+
press(dispatch, "j");
|
|
347
|
+
expect(spies.playBackward).toHaveBeenCalledTimes(1);
|
|
348
|
+
press(dispatch, "i");
|
|
349
|
+
expect(usePlayerStore.getState().inPoint).not.toBeNull();
|
|
350
|
+
press(dispatch, "o");
|
|
351
|
+
expect(usePlayerStore.getState().outPoint).not.toBeNull();
|
|
352
|
+
press(dispatch, "a");
|
|
353
|
+
press(dispatch, "e");
|
|
354
|
+
expect(spies.seek).toHaveBeenCalledTimes(2);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("a remapped key answers and the old one does not", () => {
|
|
358
|
+
setStudioKeys({ mute: "x", seekToIn: "u", shuttleForward: "y" });
|
|
359
|
+
const { dispatch, spies } = setupHook();
|
|
360
|
+
press(dispatch, "m");
|
|
361
|
+
expect(usePlayerStore.getState().audioMuted).toBe(false);
|
|
362
|
+
press(dispatch, "x");
|
|
363
|
+
expect(usePlayerStore.getState().audioMuted).toBe(true);
|
|
364
|
+
press(dispatch, "a");
|
|
365
|
+
expect(spies.seek).not.toHaveBeenCalled();
|
|
366
|
+
press(dispatch, "u");
|
|
367
|
+
expect(spies.seek).toHaveBeenCalledTimes(1);
|
|
368
|
+
press(dispatch, "l");
|
|
369
|
+
expect(spies.play).not.toHaveBeenCalled();
|
|
370
|
+
press(dispatch, "y");
|
|
371
|
+
expect(spies.play).toHaveBeenCalledTimes(1);
|
|
372
|
+
press(dispatch, "y", true);
|
|
373
|
+
expect(usePlayerStore.getState().loopEnabled).toBe(true);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it("holding the remapped stop key still frame-steps with the remapped shuttle keys", () => {
|
|
377
|
+
setStudioKeys({ pause: "p", shuttleForward: "y" });
|
|
378
|
+
const { dispatch, spies } = setupHook();
|
|
379
|
+
press(dispatch, "p");
|
|
380
|
+
press(dispatch, "y");
|
|
381
|
+
press(dispatch, "j");
|
|
382
|
+
expect(spies.seek).toHaveBeenCalledTimes(2);
|
|
383
|
+
expect(spies.play).not.toHaveBeenCalled();
|
|
384
|
+
expect(spies.playBackward).not.toHaveBeenCalled();
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it("with the razor armed, jump-to-in still answers when razor-back-to-select moved", () => {
|
|
388
|
+
setStudioKeys({ exitRazor: "x" });
|
|
389
|
+
usePlayerStore.setState({ activeTool: "razor", inPoint: 2 });
|
|
390
|
+
const { dispatch, spies } = setupHook();
|
|
391
|
+
press(dispatch, "a");
|
|
392
|
+
expect(spies.seek).toHaveBeenCalledWith(2, { keepPlaying: true });
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("with the razor armed, a remapped jump-to-in key still answers", () => {
|
|
396
|
+
setStudioKeys({ seekToIn: "q" });
|
|
397
|
+
usePlayerStore.setState({ activeTool: "razor", inPoint: 3 });
|
|
398
|
+
const { dispatch, spies } = setupHook();
|
|
399
|
+
press(dispatch, "q");
|
|
400
|
+
expect(spies.seek).toHaveBeenCalledWith(3, { keepPlaying: true });
|
|
401
|
+
});
|
|
402
|
+
});
|
|
@@ -8,9 +8,14 @@
|
|
|
8
8
|
|
|
9
9
|
import { useRef, useCallback } from "react";
|
|
10
10
|
import { useCaptionStore } from "../../captions/store";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
razorClaimsKey,
|
|
13
|
+
shouldIgnorePlaybackShortcutEvent,
|
|
14
|
+
SHUTTLE_SPEEDS,
|
|
15
|
+
} from "../lib/playbackShortcuts";
|
|
12
16
|
import { canvasNudgeKeysClaimed } from "../../utils/canvasNudgeGate";
|
|
13
17
|
import { usePlayerStore } from "../store/playerStore";
|
|
18
|
+
import { getStudioKeys } from "../components/studioShortcuts";
|
|
14
19
|
import { stepFrameTime } from "../lib/time";
|
|
15
20
|
import { useLinkedClipPreferences } from "../../utils/linkedClipPreferences";
|
|
16
21
|
import type { PlaybackAdapter } from "../lib/playbackTypes";
|
|
@@ -27,12 +32,27 @@ interface UsePlaybackKeyboardParams {
|
|
|
27
32
|
seek: (time: number, options?: { keepPlaying?: boolean }) => void;
|
|
28
33
|
}
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
function handleWorkAreaKey(
|
|
36
|
+
e: KeyboardEvent,
|
|
37
|
+
key: string,
|
|
38
|
+
getAdapter: () => PlaybackAdapter | null,
|
|
39
|
+
seek: UsePlaybackKeyboardParams["seek"],
|
|
40
|
+
): boolean {
|
|
41
|
+
if (razorClaimsKey(e, key)) return false;
|
|
42
|
+
const keys = getStudioKeys();
|
|
43
|
+
const store = usePlayerStore.getState();
|
|
44
|
+
const time = () => getAdapter()?.getTime() ?? store.currentTime;
|
|
45
|
+
const end = () => store.outPoint ?? getAdapter()?.getDuration() ?? store.duration;
|
|
46
|
+
const actions: Record<string, () => void> = {
|
|
47
|
+
[keys.inPoint]: () => store.setInPoint(e.shiftKey ? null : time()),
|
|
48
|
+
[keys.outPoint]: () => store.setOutPoint(e.shiftKey ? null : time()),
|
|
49
|
+
[keys.seekToIn]: () => seek(store.inPoint ?? 0, { keepPlaying: true }),
|
|
50
|
+
[keys.seekToOut]: () => seek(end(), { keepPlaying: true }),
|
|
51
|
+
};
|
|
52
|
+
if (!Object.hasOwn(actions, key)) return false;
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
actions[key]();
|
|
55
|
+
return true;
|
|
36
56
|
}
|
|
37
57
|
|
|
38
58
|
export function usePlaybackKeyboard({
|
|
@@ -108,6 +128,7 @@ export function usePlaybackKeyboard({
|
|
|
108
128
|
return;
|
|
109
129
|
}
|
|
110
130
|
const key = e.key.toLowerCase();
|
|
131
|
+
const keys = getStudioKeys();
|
|
111
132
|
pressedKeysRef.current.add(key);
|
|
112
133
|
if (e.code === "Space") {
|
|
113
134
|
e.preventDefault();
|
|
@@ -129,67 +150,42 @@ export function usePlaybackKeyboard({
|
|
|
129
150
|
return;
|
|
130
151
|
}
|
|
131
152
|
if (e.repeat) return;
|
|
132
|
-
if (key ===
|
|
153
|
+
if (key === keys.mute) {
|
|
133
154
|
e.preventDefault();
|
|
134
155
|
const state = usePlayerStore.getState();
|
|
135
156
|
state.setAudioMuted(!state.audioMuted);
|
|
136
157
|
return;
|
|
137
158
|
}
|
|
138
|
-
if (key ===
|
|
159
|
+
if (key === keys.shuttleForward && e.shiftKey) {
|
|
139
160
|
e.preventDefault();
|
|
140
161
|
const state = usePlayerStore.getState();
|
|
141
162
|
state.setLoopEnabled(!state.loopEnabled);
|
|
142
163
|
return;
|
|
143
164
|
}
|
|
144
|
-
if (key ===
|
|
165
|
+
if (key === keys.pause) {
|
|
145
166
|
e.preventDefault();
|
|
146
167
|
pause();
|
|
147
168
|
return;
|
|
148
169
|
}
|
|
149
|
-
if (key ===
|
|
170
|
+
if (key === keys.shuttleBack) {
|
|
150
171
|
e.preventDefault();
|
|
151
|
-
if (pressedKeysRef.current.has(
|
|
172
|
+
if (pressedKeysRef.current.has(keys.pause)) {
|
|
152
173
|
stepFrames(-1);
|
|
153
174
|
return;
|
|
154
175
|
}
|
|
155
176
|
shuttle("backward");
|
|
156
177
|
return;
|
|
157
178
|
}
|
|
158
|
-
if (key ===
|
|
179
|
+
if (key === keys.shuttleForward) {
|
|
159
180
|
e.preventDefault();
|
|
160
|
-
if (pressedKeysRef.current.has(
|
|
181
|
+
if (pressedKeysRef.current.has(keys.pause)) {
|
|
161
182
|
stepFrames(1);
|
|
162
183
|
return;
|
|
163
184
|
}
|
|
164
185
|
shuttle("forward");
|
|
165
186
|
return;
|
|
166
187
|
}
|
|
167
|
-
|
|
168
|
-
e.preventDefault();
|
|
169
|
-
const t = getAdapter()?.getTime() ?? usePlayerStore.getState().currentTime;
|
|
170
|
-
usePlayerStore.getState().setInPoint(e.shiftKey ? null : t);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
if (key === "o") {
|
|
174
|
-
e.preventDefault();
|
|
175
|
-
const t = getAdapter()?.getTime() ?? usePlayerStore.getState().currentTime;
|
|
176
|
-
usePlayerStore.getState().setOutPoint(e.shiftKey ? null : t);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
if (key === "a") {
|
|
180
|
-
if (shouldRazorClaimPlainA(e)) return;
|
|
181
|
-
e.preventDefault();
|
|
182
|
-
seek(usePlayerStore.getState().inPoint ?? 0, { keepPlaying: true });
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (key === "e") {
|
|
186
|
-
e.preventDefault();
|
|
187
|
-
const { outPoint } = usePlayerStore.getState();
|
|
188
|
-
seek(outPoint ?? getAdapter()?.getDuration() ?? usePlayerStore.getState().duration, {
|
|
189
|
-
keepPlaying: true,
|
|
190
|
-
});
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
188
|
+
handleWorkAreaKey(e, key, getAdapter, seek);
|
|
193
189
|
},
|
|
194
190
|
[pause, shuttle, stepFrames, togglePlay, getAdapter, seek],
|
|
195
191
|
);
|