feat(studio): press ? to open the keyboard shortcuts panel (#7478)

* feat(studio): press ? to open the keyboard shortcuts panel

Adds a rebindable `shortcuts` action bound to `?` (Shift+/) that toggles
the shortcuts panel; Esc still closes it. The key is ignored while focus
is in an input, textarea or contenteditable, and the panel lists `?`
under Panels.

Refs heygen-com/hyperframes#5580

* docs(studio): document the ? shortcut for the shortcuts panel
This commit is contained in:
karl songcuan
2026-11-14 18:55:54 +00:00
committed by GitHub
parent f7f2c535be
commit a03e85f43a
5 changed files with 101 additions and 4 deletions
+4
View File
@@ -70,6 +70,10 @@ share it.
Shortcuts depend on the active area. The table below covers the shortcuts
implemented by the browser editor's player, canvas, and timeline.
Press `?` (Shift + /) to open the shortcuts panel from the timeline toolbar, and
press it again or Esc to close it. It does nothing while you are typing in a text
field.
### Playback
| Shortcut | Action |
@@ -58,6 +58,20 @@ function panelOf(trigger: HTMLButtonElement): HTMLElement {
return document.getElementById(trigger.getAttribute("aria-controls")!)!;
}
function pressQuestionMark(target: Element): KeyboardEvent {
const event = new KeyboardEvent("keydown", {
key: "?",
code: "Slash",
shiftKey: true,
bubbles: true,
cancelable: true,
});
act(() => {
target.dispatchEvent(event);
});
return event;
}
describe("ShortcutsPanel", () => {
it.each(["page", "button", "panel"] as const)(
"closes with Escape from the %s-focused position",
@@ -93,6 +107,67 @@ describe("ShortcutsPanel", () => {
},
);
it("opens with ? and closes with ? again or Escape", () => {
const { trigger } = renderPanel();
pressQuestionMark(document.body);
expect(trigger.getAttribute("aria-expanded")).toBe("true");
expect(panelOf(trigger).textContent).toContain("Show / hide this panel");
pressQuestionMark(document.activeElement ?? document.body);
expect(trigger.getAttribute("aria-expanded")).toBe("false");
pressQuestionMark(document.body);
expect(trigger.getAttribute("aria-expanded")).toBe("true");
act(() => {
document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
});
expect(trigger.getAttribute("aria-expanded")).toBe("false");
});
it("does not show the button's tooltip when ? opens the panel", async () => {
const { trigger } = renderPanel();
pressQuestionMark(document.body);
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
});
expect(document.querySelector('[role="tooltip"]')).toBeNull();
expect(trigger.getAttribute("aria-describedby")).toBeNull();
});
it.each([
["an input", () => document.createElement("input")],
["a textarea", () => document.createElement("textarea")],
[
"a contenteditable",
() => {
const editable = document.createElement("div");
editable.contentEditable = "true";
return editable;
},
],
])("leaves ? to %s", (_, createField) => {
const field = createField();
document.body.append(field);
const { trigger } = renderPanel();
const event = pressQuestionMark(field);
expect(trigger.getAttribute("aria-expanded")).toBe("false");
expect(event.defaultPrevented).toBe(false);
});
it("leaves ? to the panel's own frame input while open", () => {
const { trigger } = renderPanel();
openPanel(trigger);
pressQuestionMark(document.querySelector<HTMLInputElement>('[aria-label="Jump to frame"]')!);
expect(trigger.getAttribute("aria-expanded")).toBe("true");
});
it("closes on an outside press whose pointerdown a canvas gesture prevented", () => {
const preventDefault = (event: Event) => event.preventDefault();
document.addEventListener("pointerdown", preventDefault, true);
@@ -1,10 +1,11 @@
import { useState, useCallback, useRef, memo } from "react";
import { useState, useCallback, useEffect, useRef, memo } from "react";
import { formatTime, frameToSeconds } from "../lib/time";
import { Popover, Tooltip } from "../../components/ui";
import { flatActive, flatIdle } from "../../components/timelineToolbarStyles";
import { usePlayerStore } from "../store/playerStore";
import { useCompositionFps } from "../../utils/linkedClipPreferences";
import { useShortcutSections, type ShortcutSection } from "./studioShortcuts";
import { matchesKey, useShortcutSections, type ShortcutSection } from "./studioShortcuts";
import { isTypingTarget } from "../../utils/typingTarget";
interface ShortcutsPanelProps {
disabled: boolean;
@@ -20,6 +21,21 @@ interface ShortcutsPanelProps {
/** Stays above its button, shrinking to the room there, rather than flipping down over the timeline. */
const STAY_ABOVE = { side: "none", align: "shift", fallbackAxisSide: "none" } as const;
function useShortcutsOpen() {
const [open, setOpen] = useState(false);
useEffect(() => {
const onKeyDown = (e: KeyboardEvent) => {
if (e.defaultPrevented || e.repeat || isTypingTarget(e.target)) return;
if (!matchesKey(e, "shortcuts")) return;
e.preventDefault();
setOpen((wasOpen) => !wasOpen);
};
document.addEventListener("keydown", onKeyDown);
return () => document.removeEventListener("keydown", onKeyDown);
}, []);
return [open, setOpen] as const;
}
export const ShortcutsPanel = memo(function ShortcutsPanel({
disabled,
duration,
@@ -31,7 +47,7 @@ export const ShortcutsPanel = memo(function ShortcutsPanel({
sections: hostSections,
}: ShortcutsPanelProps) {
const sections = useShortcutSections(hostSections);
const [showShortcuts, setShowShortcuts] = useState(false);
const [showShortcuts, setShowShortcuts] = useShortcutsOpen();
const [jumpFrame, setJumpFrame] = useState("");
const compositionFps = useCompositionFps();
// Focus lands on the scrolling body, not the frame input, so keyboard users can scroll and read it.
@@ -62,7 +78,7 @@ export const ShortcutsPanel = memo(function ShortcutsPanel({
);
return (
<Tooltip label="Shortcuts and tools">
<Tooltip label="Shortcuts and tools" disabled={showShortcuts}>
<Popover
open={showShortcuts}
onOpenChange={setShowShortcuts}
@@ -22,6 +22,7 @@ export const DEFAULT_STUDIO_KEYS = {
snap: "s",
grid: "g",
timelineSnap: "n",
shortcuts: "?",
playPause: "Space",
frameBack: "ArrowLeft",
frameForward: "ArrowRight",
@@ -189,6 +189,7 @@ export function buildShortcutSections(keys: StudioKeys): readonly ShortcutSectio
hints: [
{ key: k("tabCompositions"), label: "Compositions tab" },
{ key: k("tabAssets"), label: "Assets tab" },
{ key: k("shortcuts"), label: "Show / hide this panel" },
],
},
{