Skip to content

Commit 07af05c

Browse files
feat(studio): fade handles ride the fade's end and the waveform shows the fade (#4844)
* feat(studio): fade handles ride the fade's end and the waveform shows the fade * refactor(studio): read fade handle keys from one lookup * fix(studio): fade handle keys stay with the handle and snap past the clip's own edges * fix(studio): Cmd shortcuts keep working on a focused slider and fade boxes stay on their tabs * fix(studio): keep a fade handle while it is in use and restore the viewport gate's Chrome path * fix(studio): a fade's draft clears with its own save and grow drags never shrink it * fix(studio): saved fades reach the timeline store so the handle stays where it was dropped * fix(studio): a fade longer than its clip starts a drag or key from the clip's end * fix(studio): fade comments state the rule, not its history
1 parent bc57e28 commit 07af05c

22 files changed

Lines changed: 1031 additions & 275 deletions

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ jobs:
955955
node packages/studio/tests/e2e/perf-ratchet.mjs check \
956956
packages/studio/tests/e2e/perf-ceilings.json studio-open /tmp/studio-open-counts.json \
957957
/tmp/base-perf-ceilings.json
958-
- name: Measure the fade handle dots on a narrow clip
958+
- name: Measure the fade handle tabs on a narrow clip
959959
if: success() || failure()
960960
run: |
961961
set -euo pipefail

‎packages/studio/src/captions/keyboard.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ describe("shouldHandleCaptionNudgeKey", () => {
3838
expect(shouldHandleCaptionNudgeKey(mockKeyboardEvent("KeyL"))).toBe(false);
3939
});
4040

41+
it("ignores arrows a focused slider owns", () => {
42+
const slider = document.createElement("div");
43+
slider.setAttribute("role", "slider");
44+
expect(shouldHandleCaptionNudgeKey(mockKeyboardEvent("ArrowUp"), slider)).toBe(false);
45+
});
46+
4147
it("ignores arrows when the event target is an editable element", () => {
4248
const input = document.createElement("input");
4349
const textarea = document.createElement("textarea");

‎packages/studio/src/captions/keyboard.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isEditableTarget } from "../utils/timelineDiscovery";
2+
import { ownsPlainKeys } from "../utils/typingTarget";
23

34
const CAPTION_NUDGE_KEYS = new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
45

@@ -9,7 +10,7 @@ export function shouldHandleCaptionNudgeKey(
910
target?: EventTarget | null,
1011
): boolean {
1112
if (event.metaKey || event.ctrlKey || event.altKey) return false;
12-
if (target != null && isEditableTarget(target)) return false;
13+
if (target != null && ownsPlainKeys(target)) return false;
1314
return CAPTION_NUDGE_KEYS.has(event.key);
1415
}
1516

‎packages/studio/src/components/editor/useDomEditNudge.test.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,37 @@ describe("useDomEditNudge — selection cleanup keyed on stable identity", () =>
124124
element.remove();
125125
});
126126

127+
it("leaves arrows on a focused slider alone", () => {
128+
const host = document.createElement("div");
129+
document.body.append(host);
130+
const root = createRoot(host);
131+
const element = document.createElement("div");
132+
element.id = "dot-a";
133+
const slider = document.createElement("div");
134+
slider.setAttribute("role", "slider");
135+
document.body.append(element, slider);
136+
const commit = vi.fn();
137+
act(() => {
138+
root.render(
139+
React.createElement(Harness, {
140+
selection: makeSelection("Dot", element),
141+
onPathOffsetCommit: commit,
142+
}),
143+
);
144+
});
145+
act(() => {
146+
slider.dispatchEvent(
147+
new KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true, cancelable: true }),
148+
);
149+
vi.advanceTimersByTime(CANVAS_NUDGE_COMMIT_DEBOUNCE_MS + 10);
150+
});
151+
expect(commit).not.toHaveBeenCalled();
152+
act(() => root.unmount());
153+
host.remove();
154+
element.remove();
155+
slider.remove();
156+
});
157+
127158
it("still flushes the burst when the selection actually changes to a different element", () => {
128159
const host = document.createElement("div");
129160
document.body.append(host);

‎packages/studio/src/components/editor/useDomEditNudge.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import { useCallback, useEffect, useRef, type RefObject } from "react";
99
import { useMountEffect } from "../../hooks/useMountEffect";
10-
import { isTypingTarget } from "../../utils/typingTarget";
10+
import { ownsPlainKeys } from "../../utils/typingTarget";
1111
import { acquireCanvasNudgeKeys } from "../../utils/canvasNudgeGate";
1212
import type { DomEditSelection } from "./domEditing";
1313
import {
@@ -132,7 +132,7 @@ function resolveSingleNudgeTarget(
132132
function shouldIgnoreNudgeKey(p: UseDomEditNudgeParams, event: KeyboardEvent): boolean {
133133
if (!p.allowCanvasMovement || event.defaultPrevented) return true;
134134
if (p.gestureRef.current || p.groupGestureRef.current || p.blockedMoveRef.current) return true;
135-
return isTypingTarget(event.target);
135+
return ownsPlainKeys(event.target);
136136
}
137137

138138
export function useDomEditNudge(params: UseDomEditNudgeParams): { flushNudge: () => void } {

‎packages/studio/src/hooks/appHotkeysDispatch.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { usePlayerStore } from "../player";
33
import type { TimelineElement } from "../player";
44
import type { DomEditSelection } from "../components/editor/domEditing";
55
import { useDockLayoutStore } from "../components/dock/dockLayoutStore";
6-
import { isTypingTarget } from "../utils/typingTarget";
6+
import { isTypingTarget, ownsPlainKeys } from "../utils/typingTarget";
77
import { isEditableTarget } from "../utils/timelineDiscovery";
88
import { shouldIgnoreHistoryShortcut } from "../utils/studioHelpers";
99
import { canSplitElement } from "../utils/timelineElementSplit";
@@ -153,6 +153,7 @@ export function dispatchModifierKey(
153153
* Delete arbitration between keyframes, an automation range and the clip can
154154
* be asserted without standing up the whole hook. */
155155
export function dispatchPlainKey(event: KeyboardEvent, key: string, cb: HotkeyCallbacks): void {
156+
if (ownsPlainKeys(event.target)) return;
156157
if (key === STUDIO_PLAIN_KEYS.fullscreen && !event.shiftKey && !event.altKey) {
157158
event.preventDefault();
158159
if (document.fullscreenElement) void document.exitFullscreen();

‎packages/studio/src/hooks/useAppHotkeys.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,38 @@ afterEach(() => {
6060
});
6161
});
6262

63+
describe("keys on a focused slider", () => {
64+
const slider = () => {
65+
const el = document.createElement("div");
66+
el.setAttribute("role", "slider");
67+
document.body.append(el);
68+
return el;
69+
};
70+
const from = (target: HTMLElement, init: KeyboardEventInit) => {
71+
const event = new KeyboardEvent("keydown", { ...init, bubbles: true, cancelable: true });
72+
Object.defineProperty(event, "target", { value: target });
73+
return event;
74+
};
75+
76+
it("leaves Delete to the slider instead of deleting the selected clip", () => {
77+
usePlayerStore.setState({
78+
elements: [bgmElement],
79+
selectedElementId: "bgm",
80+
selectedElementIds: new Set(["bgm"]),
81+
});
82+
const cb = callbacks();
83+
dispatchPlainKey(from(slider(), { key: "Delete" }), "delete", cb);
84+
expect(cb.handleTimelineElementsDelete).not.toHaveBeenCalled();
85+
expect(cb.handleTimelineElementDelete).not.toHaveBeenCalled();
86+
});
87+
88+
it("still undoes with Cmd+Z while a slider has focus", () => {
89+
const cb = callbacks();
90+
dispatchModifierKey(from(slider(), { key: "z", metaKey: true }), "z", cb);
91+
expect(cb.handleUndo).toHaveBeenCalledTimes(1);
92+
});
93+
});
94+
6395
describe("dispatchPlainKey — select leftward / rightward", () => {
6496
const clips = [
6597
{ ...bgmElement, id: "early", key: "early", start: 0, track: 0 },

‎packages/studio/src/hooks/useAppHotkeys.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useCallback, useEffect, useRef } from "react";
22
import { usePlayerStore } from "../player";
33
import type { TimelineElement } from "../player";
44
import type { DomEditSelection } from "../components/editor/domEditing";
5-
import { isTypingTarget } from "../utils/typingTarget";
65
import { useCaptionStore } from "../captions/store";
76
import {
87
applyCaptionModelToIframe,
@@ -220,7 +219,7 @@ export function useAppHotkeys({
220219
dispatchModifierKey(event, key, cb);
221220
return;
222221
}
223-
if (!isTypingTarget(event.target)) dispatchPlainKey(event, key, cb);
222+
dispatchPlainKey(event, key, cb);
224223
}, []);
225224

226225
// eslint-disable-next-line no-restricted-syntax

‎packages/studio/src/hooks/useRenderClipContent.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import type { TimelineElement } from "../player";
1010
import type { TimelineClipRenderContext } from "../player/components/TimelineTypes";
1111
import { audioPillFlags } from "../player/components/audioClipLink";
12-
import { AudioWaveform } from "../player/components/AudioWaveform";
12+
import { AudioWaveform, rendersWaveform } from "../player/components/AudioWaveform";
1313
import { ImageThumbnail } from "../player/components/ImageThumbnail";
1414
import { encodePreviewPath, resolveMediaPreviewUrl } from "../player/components/thumbnailUtils";
1515
import { usePlayerStore } from "../player/store/playerStore";
@@ -135,7 +135,7 @@ export function useRenderClipContent({
135135
// Thumbnail generation disabled (perf) -> plain clip bars. Audio still shows
136136
// its waveform (cheap, not a frame thumbnail). Toggle: timeline toolbar.
137137
if (effectiveMode === "hidden") {
138-
return el.tag === "audio"
138+
return rendersWaveform(el)
139139
? renderAudioClip(el, pid, sessionEpoch, style.label, context, elements)
140140
: null;
141141
}
@@ -173,7 +173,7 @@ export function useRenderClipContent({
173173
// Audio clips — waveform visualization. Resolve these before the generic
174174
// activePreviewUrl thumbnail branch; audio rows need waveform data, not a
175175
// captured frame from the currently drilled composition preview.
176-
if (el.tag === "audio") {
176+
if (rendersWaveform(el)) {
177177
return renderAudioClip(el, pid, sessionEpoch, style.label, context, elements);
178178
}
179179

‎packages/studio/src/player/components/AudioWaveform.test.tsx‎

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,52 @@ afterEach(() => {
2020
document.body.innerHTML = "";
2121
});
2222

23+
/** A 6 x 20 canvas whose 2D context records every fill as [style, x, y, width, height]. */
24+
function recordingCanvas() {
25+
const fills: Array<[string, number, number, number, number]> = [];
26+
const context = {
27+
scale: vi.fn(),
28+
clearRect: vi.fn(),
29+
fillStyle: "",
30+
fillRect: (x: number, y: number, width: number, height: number) =>
31+
fills.push([String(context.fillStyle), x, y, width, height]),
32+
} as unknown as CanvasRenderingContext2D;
33+
const canvas = document.createElement("canvas");
34+
Object.defineProperties(canvas, {
35+
clientWidth: { value: 6 },
36+
clientHeight: { value: 20 },
37+
});
38+
vi.spyOn(canvas, "getContext").mockReturnValue(context);
39+
return { canvas, fills };
40+
}
41+
2342
describe("AudioWaveform", () => {
2443
it("paints a baseline and peak bar for every mapped waveform bin", () => {
25-
const fillRect = vi.fn();
26-
const context = {
27-
scale: vi.fn(),
28-
clearRect: vi.fn(),
29-
fillRect,
30-
fillStyle: "",
31-
} as unknown as CanvasRenderingContext2D;
32-
const canvas = document.createElement("canvas");
33-
Object.defineProperties(canvas, {
34-
clientWidth: { value: 6 },
35-
clientHeight: { value: 20 },
36-
});
37-
vi.spyOn(canvas, "getContext").mockReturnValue(context);
44+
const { canvas, fills } = recordingCanvas();
3845
drawWaveformCanvas(canvas, [0.25, 1], false, 0, 1);
39-
expect(fillRect).toHaveBeenCalledTimes(4);
40-
expect(fillRect.mock.calls.map(([x, y, width, height]) => [x, y, width, height])).toEqual([
46+
expect(fills.map(([, x, y, width, height]) => [x, y, width, height])).toEqual([
4147
[0, 18, 3, 2],
4248
[0, 15, 3, 5],
4349
[3, 18, 3, 2],
4450
[3, 0, 3, 20],
4551
]);
4652
});
4753

54+
it("shrinks each bar to the fade's gain and keeps the cut-away part as a ghost", () => {
55+
const { canvas, fills } = recordingCanvas();
56+
// A 1 s fade-in on a 2 s clip: the first bar's centre (0.5 s) plays at half gain.
57+
drawWaveformCanvas(canvas, [1, 1], false, 0, 1, { fadeIn: 1, fadeOut: 0, duration: 2 });
58+
const bars = fills.filter(([, , y, , height]) => !(y === 18 && height === 2));
59+
// The heard half, then the ghost only above it, so the two never stack.
60+
expect(bars.map(([, x, y, width, height]) => [x, y, width, height])).toEqual([
61+
[0, 10, 3, 10],
62+
[0, 0, 3, 10],
63+
[3, 0, 3, 20],
64+
]);
65+
const alpha = (style: string) => Number(style.split(",").at(-1)?.replace(")", ""));
66+
expect(alpha(bars[1][0])).toBeCloseTo(alpha(bars[0][0]) * 0.27, 2);
67+
});
68+
4869
it("leases waveform decoding with the clip's project, session, and viewport priority", () => {
4970
const host = document.createElement("div");
5071
document.body.append(host);

0 commit comments

Comments
 (0)