@hyperframes/studio 0.8.229 → 0.8.231
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-ClW2l0Vl.js} +1 -1
- package/dist/assets/{index-CNO8BPjF.js → index-CGfRmZQd.js} +1 -1
- package/dist/assets/{index-CrRO-B3w.js → index-DxWNzvQJ.js} +187 -187
- package/dist/index.d.ts +73 -2
- package/dist/index.html +1 -1
- package/dist/index.js +2475 -2228
- 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/TimelineToolPicker.tsx +6 -4
- package/src/components/TimelineToolbar.tsx +22 -18
- package/src/components/editor/GestureRecordControl.tsx +8 -3
- package/src/components/editor/InspectorHeaderActions.tsx +3 -1
- package/src/components/editor/PropertyPanelFlatFooter.tsx +3 -1
- package/src/components/editor/PropertyPanelFlatHeader.tsx +3 -1
- package/src/components/editor/SnapToolbar.tsx +11 -5
- 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 +104 -118
- package/src/hooks/linkShortcuts.test.ts +20 -0
- package/src/hooks/linkShortcuts.ts +11 -11
- package/src/hooks/useAppHotkeys.test.ts +201 -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/index.ts +9 -1
- package/src/player/components/BeatStrip.tsx +2 -1
- package/src/player/components/ClipContextMenu.tsx +9 -6
- package/src/player/components/PlayerControls.tsx +3 -2
- package/src/player/components/ShortcutsPanel.tsx +3 -2
- 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 +124 -0
- package/src/player/components/studioShortcuts.ts +245 -96
- 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 +164 -4
- package/src/player/hooks/usePlaybackKeyboard.ts +94 -102
- 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/hooks/useTimelinePlayer.test.ts +19 -13
- package/src/player/lib/playbackShortcuts.ts +16 -7
|
@@ -8,7 +8,8 @@ import { isEditableTarget } from "../utils/timelineDiscovery";
|
|
|
8
8
|
import { shouldIgnoreHistoryShortcut } from "../utils/studioHelpers";
|
|
9
9
|
import { canSplitElement } from "../utils/timelineElementSplit";
|
|
10
10
|
import { trackStudioEvent } from "../utils/studioTelemetry";
|
|
11
|
-
import {
|
|
11
|
+
import { razorClaimsKey } from "../player/lib/playbackShortcuts";
|
|
12
|
+
import { getStudioKeys, keyHint, matchesKey } from "../player/components/studioShortcuts";
|
|
12
13
|
import { zoomTimelineToSelectedClips } from "../player/components/timelineZoomInput";
|
|
13
14
|
import { openAudioGainDialog } from "../player/components/audioGainDialogStore";
|
|
14
15
|
import type { LinkShortcutCallbacks } from "./linkShortcuts";
|
|
@@ -18,18 +19,11 @@ import type { LinkShortcutCallbacks } from "./linkShortcuts";
|
|
|
18
19
|
// hook still owns the actual keydown listeners and calls into these.
|
|
19
20
|
|
|
20
21
|
function handleUndoRedoKey(event: KeyboardEvent, onUndo: () => void, onRedo: () => void): boolean {
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
if ((key === "z" && event.shiftKey) || (event.ctrlKey && !event.metaKey && key === "y")) {
|
|
28
|
-
event.preventDefault();
|
|
29
|
-
onRedo();
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
return false;
|
|
22
|
+
const isUndo = matchesKey(event, "undo");
|
|
23
|
+
if (!isUndo && !matchesKey(event, "redo") && !matchesKey(event, "redoAlt")) return false;
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
(isUndo ? onUndo : onRedo)();
|
|
26
|
+
return true;
|
|
33
27
|
}
|
|
34
28
|
|
|
35
29
|
export interface HotkeyCallbacks extends LinkShortcutCallbacks {
|
|
@@ -59,17 +53,80 @@ function timelineOwnsKey(event: KeyboardEvent): boolean {
|
|
|
59
53
|
return event.target instanceof Element && event.target.closest("[data-studio-timeline]") !== null;
|
|
60
54
|
}
|
|
61
55
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
function dispatchTabKey(event: KeyboardEvent): boolean {
|
|
57
|
+
const tab = matchesKey(event, "tabCompositions")
|
|
58
|
+
? ["tab_compositions", "compositions"]
|
|
59
|
+
: matchesKey(event, "tabAssets")
|
|
60
|
+
? ["tab_assets", "assets"]
|
|
61
|
+
: null;
|
|
62
|
+
if (!tab) return false;
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
trackStudioEvent("keyboard_shortcut", { action: tab[0] });
|
|
65
|
+
useDockLayoutStore.getState().activatePanel(tab[1] as "compositions" | "assets");
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function dispatchGroupKey(event: KeyboardEvent, cb: HotkeyCallbacks): boolean {
|
|
70
|
+
const group = matchesKey(event, "group");
|
|
71
|
+
if (!group && !matchesKey(event, "ungroup")) return false;
|
|
72
|
+
if (isTypingTarget(event.target)) return false;
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
if (cb.readOnlyPreview) return true;
|
|
75
|
+
if (group) cb.onGroupSelection?.();
|
|
76
|
+
else cb.onUngroupSelection?.();
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function dispatchClipboardKey(event: KeyboardEvent, cb: HotkeyCallbacks): boolean {
|
|
81
|
+
if (isEditableTarget(event.target)) return false;
|
|
82
|
+
const copy = matchesKey(event, "copy");
|
|
83
|
+
const paste = matchesKey(event, "paste");
|
|
84
|
+
const cut = matchesKey(event, "cut");
|
|
85
|
+
const duplicate = matchesKey(event, "duplicate");
|
|
86
|
+
if (!copy && !paste && !cut && !duplicate) return false;
|
|
87
|
+
// An active automation range owns copy/paste: this capture listener runs before its own, so without
|
|
88
|
+
// this both clipboards raced the same key. No preventDefault, so the downstream handler still sees it.
|
|
89
|
+
if (automationOwnsKey(event)) return true;
|
|
90
|
+
if (copy) {
|
|
91
|
+
if (cb.handleCopy()) {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
trackStudioEvent("keyboard_shortcut", { action: "copy" });
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (cb.readOnlyPreview && cb.domEditSelectionRef.current !== null && !timelineOwnsKey(event)) {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
const hasSelection =
|
|
102
|
+
usePlayerStore.getState().selectedElementId || cb.domEditSelectionRef.current;
|
|
103
|
+
if (paste) {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
trackStudioEvent("keyboard_shortcut", { action: "paste" });
|
|
106
|
+
void cb.handlePaste();
|
|
107
|
+
} else if (cut && hasSelection) {
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
trackStudioEvent("keyboard_shortcut", { action: "cut" });
|
|
110
|
+
void cb.handleCut();
|
|
111
|
+
} else if (duplicate) {
|
|
112
|
+
// Own this key even with nothing selected, or the browser's bookmark shortcut fires over the editor.
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
if (usePlayerStore.getState().selectedElementId) {
|
|
115
|
+
trackStudioEvent("keyboard_shortcut", { action: "duplicate" });
|
|
116
|
+
void cb.handleDuplicate();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Exported for tests: the shortcuts that act on the editor, each read as a combo at event time. */
|
|
65
123
|
export function dispatchModifierKey(
|
|
66
124
|
event: KeyboardEvent,
|
|
67
|
-
|
|
125
|
+
_key: string,
|
|
68
126
|
cb: HotkeyCallbacks,
|
|
69
127
|
): boolean {
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
handleUndoRedoKey(
|
|
128
|
+
if (!shouldIgnoreHistoryShortcut(event.target)) {
|
|
129
|
+
const handled = handleUndoRedoKey(
|
|
73
130
|
event,
|
|
74
131
|
() => {
|
|
75
132
|
trackStudioEvent("keyboard_shortcut", { action: "undo" });
|
|
@@ -79,91 +136,26 @@ export function dispatchModifierKey(
|
|
|
79
136
|
trackStudioEvent("keyboard_shortcut", { action: "redo" });
|
|
80
137
|
void cb.handleRedo();
|
|
81
138
|
},
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
return true;
|
|
85
|
-
|
|
86
|
-
if (event.key === "1") {
|
|
87
|
-
event.preventDefault();
|
|
88
|
-
trackStudioEvent("keyboard_shortcut", { action: "tab_compositions" });
|
|
89
|
-
useDockLayoutStore.getState().activatePanel("compositions");
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
if (event.key === "2") {
|
|
93
|
-
event.preventDefault();
|
|
94
|
-
trackStudioEvent("keyboard_shortcut", { action: "tab_assets" });
|
|
95
|
-
useDockLayoutStore.getState().activatePanel("assets");
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (key === "g" && !event.altKey && !isTypingTarget(event.target)) {
|
|
100
|
-
event.preventDefault();
|
|
101
|
-
if (cb.readOnlyPreview) return true;
|
|
102
|
-
if (event.shiftKey) cb.onUngroupSelection?.();
|
|
103
|
-
else cb.onGroupSelection?.();
|
|
104
|
-
return true;
|
|
139
|
+
);
|
|
140
|
+
if (handled) return true;
|
|
105
141
|
}
|
|
106
|
-
|
|
107
|
-
if (!event.shiftKey && !event.altKey && !isEditableTarget(event.target)) {
|
|
108
|
-
// An active automation range owns Cmd+C/Cmd+V, same as Delete below: this
|
|
109
|
-
// capture listener runs before useAutomationSelectionKeyboard's, so without
|
|
110
|
-
// this both clipboards raced the same key. No preventDefault, so the
|
|
111
|
-
// downstream handler still sees it.
|
|
112
|
-
if (automationOwnsKey(event)) return true;
|
|
113
|
-
if (key === "c") {
|
|
114
|
-
if (cb.handleCopy()) {
|
|
115
|
-
event.preventDefault();
|
|
116
|
-
trackStudioEvent("keyboard_shortcut", { action: "copy" });
|
|
117
|
-
}
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
const previewOwnsMutation =
|
|
121
|
-
cb.readOnlyPreview && cb.domEditSelectionRef.current !== null && !timelineOwnsKey(event);
|
|
122
|
-
if (previewOwnsMutation && ["v", "x", "d"].includes(key)) {
|
|
123
|
-
event.preventDefault();
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
if (key === "v") {
|
|
127
|
-
event.preventDefault();
|
|
128
|
-
trackStudioEvent("keyboard_shortcut", { action: "paste" });
|
|
129
|
-
void cb.handlePaste();
|
|
130
|
-
return true;
|
|
131
|
-
}
|
|
132
|
-
if (key === "x") {
|
|
133
|
-
if (usePlayerStore.getState().selectedElementId || cb.domEditSelectionRef.current) {
|
|
134
|
-
event.preventDefault();
|
|
135
|
-
trackStudioEvent("keyboard_shortcut", { action: "cut" });
|
|
136
|
-
void cb.handleCut();
|
|
137
|
-
}
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
if (key === "d") {
|
|
141
|
-
// Always own this key here, even with nothing selected — otherwise the
|
|
142
|
-
// browser's own Cmd+D (bookmark this page) fires over the editor.
|
|
143
|
-
event.preventDefault();
|
|
144
|
-
if (usePlayerStore.getState().selectedElementId) {
|
|
145
|
-
trackStudioEvent("keyboard_shortcut", { action: "duplicate" });
|
|
146
|
-
void cb.handleDuplicate();
|
|
147
|
-
}
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return false;
|
|
142
|
+
return dispatchTabKey(event) || dispatchGroupKey(event, cb) || dispatchClipboardKey(event, cb);
|
|
152
143
|
}
|
|
153
144
|
|
|
154
145
|
// fallow-ignore-next-line complexity
|
|
155
146
|
/** Exported for tests: the unmodified-key half of the dispatcher, so the
|
|
156
147
|
* Delete arbitration between keyframes, an automation range and the clip can
|
|
157
148
|
* be asserted without standing up the whole hook. */
|
|
158
|
-
export function dispatchPlainKey(event: KeyboardEvent,
|
|
149
|
+
export function dispatchPlainKey(event: KeyboardEvent, _key: string, cb: HotkeyCallbacks): void {
|
|
159
150
|
if (ownsPlainKeys(event.target)) return;
|
|
160
|
-
|
|
151
|
+
const keys = getStudioKeys();
|
|
152
|
+
if (matchesKey(event, "zoomSelection")) {
|
|
161
153
|
if (!zoomTimelineToSelectedClips()) return;
|
|
162
154
|
event.preventDefault();
|
|
163
155
|
return;
|
|
164
156
|
}
|
|
165
157
|
|
|
166
|
-
if (
|
|
158
|
+
if (matchesKey(event, "fullscreen")) {
|
|
167
159
|
event.preventDefault();
|
|
168
160
|
if (document.fullscreenElement) void document.exitFullscreen();
|
|
169
161
|
else
|
|
@@ -171,7 +163,7 @@ export function dispatchPlainKey(event: KeyboardEvent, key: string, cb: HotkeyCa
|
|
|
171
163
|
return;
|
|
172
164
|
}
|
|
173
165
|
|
|
174
|
-
if (event
|
|
166
|
+
if (matchesKey(event, "split")) {
|
|
175
167
|
// Reserve bare `s` for Split even when the current selection cannot split,
|
|
176
168
|
// so secondary listeners do not reinterpret the same key as Snap toggle.
|
|
177
169
|
event.preventDefault();
|
|
@@ -192,54 +184,53 @@ export function dispatchPlainKey(event: KeyboardEvent, key: string, cb: HotkeyCa
|
|
|
192
184
|
// that isn't in the raw `elements` list, so the s-key can't resolve them.
|
|
193
185
|
// Nudge toward the razor tool instead of failing silently.
|
|
194
186
|
if (!el && selectedElementId.includes("#")) {
|
|
195
|
-
cb.showToast(
|
|
187
|
+
cb.showToast(
|
|
188
|
+
`Use the razor tool (${keyHint("razorTool", keys)}) to split clips inside a sub-composition`,
|
|
189
|
+
"info",
|
|
190
|
+
);
|
|
196
191
|
return;
|
|
197
192
|
}
|
|
198
193
|
}
|
|
199
194
|
}
|
|
200
195
|
|
|
201
196
|
// Only with a sound clip selected, so bare G still reaches the canvas grid toggle otherwise.
|
|
202
|
-
if (
|
|
197
|
+
if (matchesKey(event, "audioGain")) {
|
|
203
198
|
if (!cb.readOnlyPreview && openAudioGainDialog()) {
|
|
204
199
|
event.preventDefault();
|
|
205
200
|
return;
|
|
206
201
|
}
|
|
207
202
|
}
|
|
208
203
|
|
|
209
|
-
if (
|
|
204
|
+
if (matchesKey(event, "razorTool")) {
|
|
210
205
|
event.preventDefault();
|
|
211
206
|
const { activeTool, setActiveTool } = usePlayerStore.getState();
|
|
212
207
|
setActiveTool(activeTool === "razor" ? "select" : "razor");
|
|
213
208
|
return;
|
|
214
209
|
}
|
|
215
210
|
|
|
216
|
-
if (
|
|
211
|
+
if (matchesKey(event, "selectTool")) {
|
|
217
212
|
event.preventDefault();
|
|
218
213
|
usePlayerStore.getState().setActiveTool("select");
|
|
219
214
|
return;
|
|
220
215
|
}
|
|
221
216
|
|
|
222
|
-
|
|
217
|
+
const leftward = matchesKey(event, "selectLeftward");
|
|
218
|
+
if (leftward || matchesKey(event, "selectRightward")) {
|
|
223
219
|
event.preventDefault();
|
|
224
220
|
const store = usePlayerStore.getState();
|
|
225
|
-
if (
|
|
221
|
+
if (leftward) store.selectLeftward();
|
|
226
222
|
else store.selectRightward();
|
|
227
223
|
return;
|
|
228
224
|
}
|
|
229
225
|
|
|
230
|
-
// CapCut returns to the select tool with "A"
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (activeTool === "razor") {
|
|
236
|
-
event.preventDefault();
|
|
237
|
-
setActiveTool("select");
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
226
|
+
// CapCut returns to the select tool with "A"; playback's seek-to-in asks the same razorClaimsKey.
|
|
227
|
+
if (razorClaimsKey(event)) {
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
usePlayerStore.getState().setActiveTool("select");
|
|
230
|
+
return;
|
|
240
231
|
}
|
|
241
232
|
|
|
242
|
-
if (event
|
|
233
|
+
if (matchesKey(event, "cancel")) {
|
|
243
234
|
const { activeTool, selectedElementId, setActiveTool, setSelectedElementId } =
|
|
244
235
|
usePlayerStore.getState();
|
|
245
236
|
if (activeTool === "razor") {
|
|
@@ -250,7 +241,7 @@ export function dispatchPlainKey(event: KeyboardEvent, key: string, cb: HotkeyCa
|
|
|
250
241
|
}
|
|
251
242
|
}
|
|
252
243
|
|
|
253
|
-
if ((event
|
|
244
|
+
if (matchesKey(event, "deleteSelected") || matchesKey(event, "deleteSelectedAlt")) {
|
|
254
245
|
if (usePlayerStore.getState().selectedKeyframes.size > 0) {
|
|
255
246
|
cb.onDeleteSelectedKeyframes();
|
|
256
247
|
usePlayerStore.getState().clearSelectedKeyframes();
|
|
@@ -262,7 +253,7 @@ export function dispatchPlainKey(event: KeyboardEvent, key: string, cb: HotkeyCa
|
|
|
262
253
|
// is what lets the document-level handler still see the key instead of
|
|
263
254
|
// the press reaching the clip delete below.
|
|
264
255
|
if (usePlayerStore.getState().automationSelection) return;
|
|
265
|
-
if (event
|
|
256
|
+
if (matchesKey(event, "resetKeyframes")) {
|
|
266
257
|
const { selectedElementId, keyframeCache } = usePlayerStore.getState();
|
|
267
258
|
if (selectedElementId && keyframeCache.has(selectedElementId) && cb.onResetKeyframes()) {
|
|
268
259
|
event.preventDefault();
|
|
@@ -295,12 +286,7 @@ export function dispatchPlainKey(event: KeyboardEvent, key: string, cb: HotkeyCa
|
|
|
295
286
|
return;
|
|
296
287
|
}
|
|
297
288
|
|
|
298
|
-
if (
|
|
299
|
-
event.key === STUDIO_PLAIN_KEYS.record &&
|
|
300
|
-
!event.shiftKey &&
|
|
301
|
-
!event.altKey &&
|
|
302
|
-
cb.onToggleRecording
|
|
303
|
-
) {
|
|
289
|
+
if (matchesKey(event, "record") && cb.onToggleRecording) {
|
|
304
290
|
event.preventDefault();
|
|
305
291
|
cb.onToggleRecording();
|
|
306
292
|
}
|
|
@@ -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,8 @@ 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";
|
|
10
|
+
import { setStudioKeys } from "../player/components/studioShortcuts";
|
|
9
11
|
import { useAudioGainDialogStore } from "../player/components/audioGainDialogStore";
|
|
10
12
|
import {
|
|
11
13
|
cancelTimelineZoom,
|
|
@@ -55,6 +57,8 @@ const chord = (key: string) =>
|
|
|
55
57
|
new KeyboardEvent("keydown", { key, metaKey: true, bubbles: true, cancelable: true });
|
|
56
58
|
|
|
57
59
|
afterEach(() => {
|
|
60
|
+
setStudioKeys(null);
|
|
61
|
+
usePlayerStore.getState().setActiveTool("select");
|
|
58
62
|
clearAutomationClipboard();
|
|
59
63
|
usePlayerStore.getState().clearAutomationSelection();
|
|
60
64
|
usePlayerStore.setState({
|
|
@@ -583,3 +587,200 @@ describe("dispatchPlainKey — G opens Audio Gain", () => {
|
|
|
583
587
|
expect(event.defaultPrevented).toBe(false);
|
|
584
588
|
});
|
|
585
589
|
});
|
|
590
|
+
|
|
591
|
+
describe("editor keys the host can remap", () => {
|
|
592
|
+
const dispatch = (key: string) => {
|
|
593
|
+
const event = press(key);
|
|
594
|
+
dispatchPlainKey(event, key.toLowerCase(), callbacks());
|
|
595
|
+
return event;
|
|
596
|
+
};
|
|
597
|
+
const tool = () => usePlayerStore.getState().activeTool;
|
|
598
|
+
|
|
599
|
+
it("answers every default key", () => {
|
|
600
|
+
dispatch("b");
|
|
601
|
+
expect(tool()).toBe("razor");
|
|
602
|
+
dispatch("a");
|
|
603
|
+
expect(tool()).toBe("select");
|
|
604
|
+
dispatch("b");
|
|
605
|
+
dispatch("v");
|
|
606
|
+
expect(tool()).toBe("select");
|
|
607
|
+
const original = usePlayerStore.getState().selectLeftward;
|
|
608
|
+
const left = vi.fn();
|
|
609
|
+
usePlayerStore.setState({ selectLeftward: left });
|
|
610
|
+
dispatch("[");
|
|
611
|
+
usePlayerStore.setState({ selectLeftward: original });
|
|
612
|
+
expect(left).toHaveBeenCalledTimes(1);
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
it("a remapped key answers and the old one does not", () => {
|
|
616
|
+
setStudioKeys({ razorTool: "y", selectTool: "u", exitRazor: "q" });
|
|
617
|
+
dispatch("b");
|
|
618
|
+
expect(tool()).toBe("select");
|
|
619
|
+
expect(dispatch("y").defaultPrevented).toBe(true);
|
|
620
|
+
expect(tool()).toBe("razor");
|
|
621
|
+
dispatch("a");
|
|
622
|
+
expect(tool()).toBe("razor");
|
|
623
|
+
dispatch("q");
|
|
624
|
+
expect(tool()).toBe("select");
|
|
625
|
+
dispatch("y");
|
|
626
|
+
dispatch("v");
|
|
627
|
+
expect(tool()).toBe("razor");
|
|
628
|
+
dispatch("u");
|
|
629
|
+
expect(tool()).toBe("select");
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
it("split, fullscreen and record follow the map", () => {
|
|
633
|
+
setStudioKeys({ split: "t", record: "w" });
|
|
634
|
+
const cb = callbacks({ onToggleRecording: vi.fn() });
|
|
635
|
+
dispatchPlainKey(press("r"), "r", cb);
|
|
636
|
+
expect(cb.onToggleRecording).not.toHaveBeenCalled();
|
|
637
|
+
dispatchPlainKey(press("w"), "w", cb);
|
|
638
|
+
expect(cb.onToggleRecording).toHaveBeenCalledTimes(1);
|
|
639
|
+
expect(press("s").defaultPrevented).toBe(false);
|
|
640
|
+
const split = press("t");
|
|
641
|
+
dispatchPlainKey(split, "t", cb);
|
|
642
|
+
expect(split.defaultPrevented).toBe(true);
|
|
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
|
|