From 950352f7ec4bd0e5f101cb9a94db2fee38248d15 Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Fri, 25 Sep 2026 13:57:12 +0200 Subject: [PATCH] Added shortcuts menu --- CLAUDE.md | 2 +- frontend/src/components/SettingsMenu.tsx | 16 ++- frontend/src/components/ShortcutsDialog.tsx | 141 ++++++++++++++++++++ 3 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 frontend/src/components/ShortcutsDialog.tsx diff --git a/CLAUDE.md b/CLAUDE.md index 3c906ee..db0667f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -342,7 +342,7 @@ Two independent apps that talk over HTTP: same menu and the row's hover buttons, which share one set of actions. A Traktor folder's id is its PATH of names, so the `PATCH`/`DELETE` playlist routes take a `:path` param, a folder name may not contain `/`, - and renaming onto a sibling folder's name is refused), `SaveBar` (+ the settings gear beside it), `Toolbar` (search/filters; columns are chosen by right-clicking the table header), + and renaming onto a sibling folder's name is refused), `SaveBar` (+ the settings gear beside it, whose menu opens `ShortcutsDialog` — the shortcut list is written out BY HAND, so a new or changed shortcut in `PrepStrip` / `TrackTable` must be added there too), `Toolbar` (search/filters; columns are chosen by right-clicking the table header), `TrackTable` (**the one track list** — All Tracks, playlists, exports and devices. TanStack Table + **virtualized** grid; per-row play button, configurable columns, header sorting, inline double-click editing, and diff --git a/frontend/src/components/SettingsMenu.tsx b/frontend/src/components/SettingsMenu.tsx index b818d5d..49ac5d5 100644 --- a/frontend/src/components/SettingsMenu.tsx +++ b/frontend/src/components/SettingsMenu.tsx @@ -1,4 +1,5 @@ import { useEffect, useRef, useState } from 'react' +import { ShortcutsDialog } from './ShortcutsDialog' interface Props { onOpenPathMapping: () => void @@ -7,9 +8,11 @@ interface Props { } /** Overflow menu for low-frequency, collection-level settings. Currently holds - * path remapping; the natural home for future advanced settings. */ + * path remapping and the shortcut list; the natural home for future advanced + * settings. The shortcuts dialog is owned here, since nothing else opens it. */ export function SettingsMenu({ onOpenPathMapping, up = false }: Props) { const [open, setOpen] = useState(false) + const [showShortcuts, setShowShortcuts] = useState(false) const ref = useRef(null) useEffect(() => { @@ -63,8 +66,19 @@ export function SettingsMenu({ onOpenPathMapping, up = false }: Props) { Point the collection at moved or relocated files + )} + {showShortcuts && setShowShortcuts(false)} />} ) } diff --git a/frontend/src/components/ShortcutsDialog.tsx b/frontend/src/components/ShortcutsDialog.tsx new file mode 100644 index 0000000..199816b --- /dev/null +++ b/frontend/src/components/ShortcutsDialog.tsx @@ -0,0 +1,141 @@ +import { useEffect } from 'react' +import { useCaps } from '../lib/capabilities' + +interface Props { + onClose: () => void +} + +// Cmd on macOS, Ctrl elsewhere — the handlers accept either, but a list that +// says "Cmd/Ctrl" everywhere is harder to scan than one that names your key. +const IS_MAC = /Mac|iPhone|iPad/.test(navigator.userAgent) +const MOD = IS_MAC ? '⌘' : 'Ctrl' + +type Row = { keys: string[][]; action: string } +type Section = { title: string; rows: Row[] } + +/** Hotcue keys are digits in pad order, 0 being the tenth, so the list follows + * the loaded library's bank size rather than hard-coding eight. */ +function hotcueKeys(slots: number): string { + const n = Math.min(slots, 10) + if (n <= 0) return '1' + if (n <= 9) return `1–${n}` + return '1–9, 0' +} + +function sections(slots: number): Section[] { + const pads = hotcueKeys(slots) + return [ + { + title: 'Deck', + rows: [ + { keys: [['Space']], action: 'Play / pause' }, + { keys: [['C']], action: 'CUE — jump back, set, or hold to preview' }, + { keys: [['←'], ['→']], action: 'Beat jump back / forward' }, + { keys: [[MOD, '↓'], [MOD, '↑']], action: 'Smaller / larger beat jump' }, + { keys: [['Shift', '←'], ['Shift', '→']], action: 'Previous / next grid marker' }, + { keys: [[pads]], action: 'Hotcue — set if empty, else jump (hold to preview)' }, + { keys: [['Shift', pads]], action: 'Delete hotcue' }, + { keys: [['Drag waveform']], action: 'Scratch' }, + ], + }, + { + title: 'Track list', + rows: [ + { keys: [['Enter']], action: 'Load and play the highlighted track' }, + { keys: [['↑'], ['↓']], action: 'Move the selection' }, + { keys: [['Shift', '↑'], ['Shift', '↓']], action: 'Extend the selection' }, + { keys: [[MOD, 'A']], action: 'Select all' }, + { keys: [['Esc']], action: 'Clear the selection' }, + { keys: [['Delete']], action: 'Remove from this playlist' }, + { keys: [['Shift', 'Click']], action: 'Select a range' }, + { keys: [[MOD, 'Click']], action: 'Add to / remove from the selection' }, + { keys: [['Double-click']], action: 'Edit a cell' }, + { keys: [['Right-click']], action: 'Track menu (header: choose columns)' }, + ], + }, + { + title: 'Sidebar', + rows: [{ keys: [['Right-click']], action: 'New playlist or folder, rename, delete' }], + }, + { + title: 'Fields & dialogs', + rows: [ + { keys: [['Enter']], action: 'Save the edit / confirm' }, + { keys: [['Esc']], action: 'Cancel / close' }, + ], + }, + ] +} + +function Keys({ combo }: { combo: string[] }) { + return ( + + {combo.map((k, i) => ( + + {k} + + ))} + + ) +} + +/** Every keyboard shortcut (and the mouse gestures that go with them), from the + * settings menu. Keep in step with the handlers in `PrepStrip` and `TrackTable` + * — this list is written out by hand, not derived from them. */ +export function ShortcutsDialog({ onClose }: Props) { + const slots = useCaps().cues.hotcue_slots + + useEffect(() => { + const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose() + window.addEventListener('keydown', onKey) + return () => window.removeEventListener('keydown', onKey) + }, [onClose]) + + return ( +
+
e.stopPropagation()} + > +
+
Keyboard Shortcuts
+ +
+
+ {sections(slots).map((s) => ( +
+
+ {s.title} +
+
+ {s.rows.map((r, i) => ( +
+ {r.action} + + {r.keys.map((combo, j) => ( + + ))} + +
+ ))} +
+
+ ))} +
+
+
+ ) +}