Changed option keyboard shortcuts to use command instead

This commit is contained in:
patben8 committed 2026-10-15 16:36:10 +02:00
1 parent 32cfb034e2
commit 16c3552be6
9 files changed
+72 -56

No files matched your search

+4 -5
View File
@@ -2,6 +2,7 @@ import { useEffect, useRef } from 'react'
import type { CuePoint } from '../api'
import type { BeatGrid } from '../lib/beatgrid'
import { Icon } from '../lib/icons'
import { hasMod, MOD_NAME } from '../lib/modKey'
import { drawBeatgrid, drawCuePoint, drawCues, drawLoop, drawLoopIn, drawPlayhead } from '../lib/cues'
import { laneScales, makeSpans, paintRaw, rawSpans, tintAt, type RawWave } from '../lib/rawWave'
import { paintLane, paintWave, type WaveColumn } from '../lib/waveform'
@@ -38,7 +39,7 @@ interface Props {
onScratchEnd: (t: number) => void
/** A stem track: one lane per stem instead of the three-band mix view. */
lanes?: StemLane[] | null
/** Click = mute toggle; Alt/Option-click = solo (mute all the others). */
/** Click = mute toggle; Cmd/Ctrl-click = solo (mute all the others). */
onStemToggle?: (index: number, solo: boolean) => void
}
@@ -56,8 +57,6 @@ export interface StemLane {
shortcut: string
}
const ALT = typeof navigator !== 'undefined' && /Mac/.test(navigator.platform) ? 'Option' : 'Alt'
const DRAG_THRESHOLD = 3 // px before a press becomes a scratch (vs a click-seek)
export const MIN_SEC = 0.25 // most zoomed-in (seconds across the view): a kick's attack spans dozens of px
@@ -277,8 +276,8 @@ export function MainWaveform({
<div key={k} className="flex flex-1 items-center">
<button
onPointerDown={(e) => e.stopPropagation()}
onClick={(e) => onStemToggle?.(k, e.altKey)}
title={`${lane.name} — click to mute, ${ALT}-click to mute all the others (${lane.shortcut})`}
onClick={(e) => onStemToggle?.(k, hasMod(e))}
title={`${lane.name} — click to mute, ${MOD_NAME}-click to mute all the others (${lane.shortcut})`}
aria-pressed={lane.audible}
className={`flex h-5 min-w-5 items-center justify-center rounded-md px-1 font-mono text-[10px] font-semibold backdrop-blur-md transition-opacity ${
lane.audible ? '' : 'opacity-40'
+3 -3
View File
@@ -55,7 +55,7 @@ export function ShortcutsDialog({ onClose }: Props) {
const [pressed, setPressed] = useState<string | null>(null)
const [query, setQuery] = useState('')
const [areas, setAreas] = useState<ReadonlySet<Area>>(new Set(ALL_AREAS))
const layer: Layer = held.has('mod') ? 'mod' : held.has('alt') ? 'alt' : held.has('shift') ? 'shift' : sticky
const layer: Layer = held.has('mod') ? 'mod' : held.has('shift') ? 'shift' : sticky
const q = query.trim().toLowerCase()
// ---- fit: one key unit from the width the map has ----
@@ -430,8 +430,8 @@ function Caption({
<>
<span className="text-text">Point at a key, or press it, to see what it does.</span>
<span className="text-xs">
Hold <Kbd>{MODIFIER_KEY.shift}</Kbd> <Kbd>{MODIFIER_KEY.mod}</Kbd> or <Kbd>{MODIFIER_KEY.alt}</Kbd>, or pick
one above, to see what each modifier changes.
Hold <Kbd>{MODIFIER_KEY.shift}</Kbd> or <Kbd>{MODIFIER_KEY.mod}</Kbd>, or pick one above, to see what each
modifier changes.
</span>
<span className="text-xs">
{padRange(slots)} are this library's {slots} hotcue pads; Q W E R are the stems of a stem track.
+8 -8
View File
@@ -114,9 +114,9 @@ interface RowActions {
onCancelDraft: () => void
/** Whether a drag of tracks (or of files from the OS) may drop on this playlist. */
acceptsTracks: (node: PlaylistNode, p: TracksOrFiles) => boolean
/** Tracks dropped on a playlist; `alt` (Option) moves them out of the
/** Tracks dropped on a playlist; `mod` (Cmd/Ctrl) moves them out of the
* playlist they came from. */
onDropTracks: (node: PlaylistNode, p: TracksOrFiles, alt: boolean) => void
onDropTracks: (node: PlaylistNode, p: TracksOrFiles, mod: boolean) => void
/** Whether a node may be dragged elsewhere in the tree. */
canMove: (node: PlaylistNode) => boolean
/** A node dropped in the tree: `index` among `parentId`'s children,
@@ -227,8 +227,8 @@ function NodeRow({
// drop TARGET for tracks. Whether it takes them is the node's own
// `can_add_tracks` plus the library being writable, decided by the sidebar.
const startDrag = usePressToDrag(() => (renaming ? null : { kind: 'node', node, parentId }))
const moves = (p: DragPayload, alt: boolean) =>
p.kind === 'tracks' && alt && !!p.fromPlaylist && p.fromPlaylist !== node.id
const moves = (p: DragPayload, mod: boolean) =>
p.kind === 'tracks' && mod && !!p.fromPlaylist && p.fromPlaylist !== node.id
// A node held over this row: which zone, and where that puts it. Never into
// itself or anything nested in it; a drop that would leave it exactly where
@@ -267,14 +267,14 @@ function NodeRow({
if (h.zone === 'tracks') {
if (p.kind === 'tracks' && p.origin === 'device') return `Import into ${node.name}…`
if ((p.kind === 'tracks' && p.origin === 'folder') || p.kind === 'files') return `Add to ${node.name}…`
return `${moves(p, at.alt) ? 'Move' : 'Add'} to ${node.name}`
return `${moves(p, at.mod) ? 'Move' : 'Add'} to ${node.name}`
}
if (h.zone === 'peek') return null
return h.zone === 'into' || h.zone === 'first' ? `Move into ${node.name}` : `Move ${h.zone} ${node.name}`
},
onDrop: (p, h, at) => {
if (p.kind !== 'node') {
if (h.zone === 'tracks') actions.onDropTracks(node, p, at.alt)
if (h.zone === 'tracks') actions.onDropTracks(node, p, at.mod)
} else if ('parentId' in h) {
actions.onMoveNode(p.node, h.parentId, h.index, h.zone === 'into' && !expanded ? node : null)
}
@@ -678,7 +678,7 @@ export function Sidebar({
onError((e as Error).message)
}
},
onDropTracks: async (node, p, alt) => {
onDropTracks: async (node, p, mod) => {
if (p.kind === 'files') {
onAddForeign('dropped', p.paths, { kind: 'playlist', id: node.id, name: node.name })
return
@@ -693,7 +693,7 @@ export function Sidebar({
playlist: node,
ids: p.ids,
duplicatesAllowed: caps.playlists.duplicates,
moveFrom: alt ? p.fromPlaylist : undefined,
moveFrom: mod ? p.fromPlaylist : undefined,
})
if (msg) onDone(msg)
} catch (e) {
+6 -3
View File
@@ -31,6 +31,7 @@ import {
import { CSS } from '@dnd-kit/utilities'
import type { Track, TrackOrigin } from '../api'
import { beginDrag, useDragPayload, useDropTarget } from '../lib/drag'
import { hasMod } from '../lib/modKey'
import { TRACK_COLUMNS } from '../lib/trackColumns'
/** Fields this platform can persist, for the table's per-cell edit gating.
@@ -73,7 +74,7 @@ interface Props {
* active: reordering a partial or re-sorted list would lose the real order. */
reorder?: { enabled: boolean; onReorder: (ids: string[]) => void }
/** Where dragged rows come from: whose ids they are, and the editable
* playlist they leave on an Option-drag (move). Defaults to the collection. */
* playlist they leave on a Cmd/Ctrl-drag (move). Defaults to the collection. */
dragFrom?: { origin: TrackOrigin; playlistId?: string }
/** Delete/Backspace removes the selected tracks from this view. */
onRemove?: (ids: string[]) => void
@@ -432,7 +433,7 @@ export function TrackTable({
fromPlaylist: from?.playlistId,
source: tableKey,
},
{ x: e.clientX, y: e.clientY, alt: e.altKey },
{ x: e.clientX, y: e.clientY, mod: hasMod(e) },
)
}
const release = () => (pressRef.current = null)
@@ -580,7 +581,9 @@ export function TrackTable({
if (selection && (e.shiftKey || e.metaKey || e.ctrlKey)) e.preventDefault()
}}
onPointerDown={(e) => {
if (e.button !== 0 || e.shiftKey || e.metaKey || e.ctrlKey) return
// Cmd/Ctrl arms a drag too (it MOVES the tracks); without
// movement it stays a Cmd/Ctrl-click, which toggles the row.
if (e.button !== 0 || e.shiftKey || (!hasMod(e) && (e.metaKey || e.ctrlKey))) return
// Not from a control inside the row (play, stars, an edit field).
if ((e.target as HTMLElement).closest('button, input, textarea, select, a')) return
pressRef.current = { x: e.clientX, y: e.clientY, index: vr.index }
+1 -1
View File
@@ -13,7 +13,7 @@ const plural = (n: number) => `${n} track${n === 1 ? '' : 's'}`
* elsewhere they are skipped and the message says so. Nothing is asked when
* there are none.
*
* `moveFrom` is an Option-drag out of another (editable) playlist: once the
* `moveFrom` is a Cmd/Ctrl-drag out of another (editable) playlist: once the
* tracks are in the target they leave the source. Cancelling the duplicates
* question cancels the move too.
*
+17 -16
View File
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useSyncExternalStore } from 'react'
import { createPortal } from 'react-dom'
import type { PlaylistNode, Track, TrackOrigin } from '../api'
import { Icon } from './icons'
import { hasMod, MOD_KEY } from './modKey'
/**
* Drag and drop across the whole window: track rows onto sidebar playlists,
@@ -38,7 +39,7 @@ export type DragPayload =
/** Which library the ids belong to — a device's or a folder's are not
* the collection's, so collection targets must not take them as such. */
origin: TrackOrigin
/** The editable playlist they were dragged out of, for Option = move. */
/** The editable playlist they were dragged out of, for Cmd/Ctrl = move. */
fromPlaylist?: string
/** Identity of the table that started the drag (its own reorder target). */
source: object
@@ -54,8 +55,8 @@ export type TracksOrFiles = Exclude<DragPayload, { kind: 'node' }>
export interface DropPoint {
x: number
y: number
/** Option/Alt held: tracks dragged out of a playlist MOVE instead of copy. */
alt: boolean
/** Cmd (macOS) / Ctrl held: tracks dragged out of a playlist MOVE instead of copy. */
mod: boolean
}
export interface DropSpec<H> {
@@ -73,13 +74,13 @@ interface State {
payload: DragPayload | null
x: number
y: number
alt: boolean
mod: boolean
target: HTMLElement | null
hint: unknown
label: string | null
}
const IDLE: State = { payload: null, x: 0, y: 0, alt: false, target: null, hint: null, label: null }
const IDLE: State = { payload: null, x: 0, y: 0, mod: false, target: null, hint: null, label: null }
let state: State = IDLE
const listeners = new Set<() => void>()
const targets = new Map<HTMLElement, { current: DropSpec<unknown> }>()
@@ -107,9 +108,9 @@ function sameHint(a: unknown, b: unknown): boolean {
/** Find the innermost target under the pointer that accepts, and record its hint. */
function evaluate() {
const { payload, x, y, alt } = state
const { payload, x, y, mod } = state
if (!payload) return
const at = { x, y, alt }
const at = { x, y, mod }
let el = document.elementFromPoint(x, y) as HTMLElement | null
while (el) {
const spec = targets.get(el)
@@ -130,19 +131,19 @@ let detach: (() => void) | null = null
/** End the drag in progress, dropping on the target under the pointer if `drop`. */
function finish(drop: boolean) {
const { payload: p, target, hint, x, y, alt } = state
const { payload: p, target, hint, x, y, mod } = state
detach?.()
if (!drop || !p || !target) return
const spec = targets.get(target)
try {
spec?.current.onDrop(p, hint, { x, y, alt })
spec?.current.onDrop(p, hint, { x, y, mod })
} catch (err) {
console.error('drop failed', err)
}
}
/** Publish a new drag and start edge auto-scroll. Returns what undoes both. */
function open(payload: DragPayload, at: { x: number; y: number; alt: boolean }): () => void {
function open(payload: DragPayload, at: { x: number; y: number; mod: boolean }): () => void {
detach?.()
set({ ...IDLE, payload, ...at })
document.documentElement.classList.add('is-dragging')
@@ -188,12 +189,12 @@ function open(payload: DragPayload, at: { x: number; y: number; alt: boolean }):
}
/** Start a drag. Call it once the press has moved past the source's threshold. */
export function beginDrag(payload: DragPayload, at: { x: number; y: number; alt: boolean }) {
export function beginDrag(payload: DragPayload, at: { x: number; y: number; mod: boolean }) {
const close = open(payload, at)
const onMove = (e: PointerEvent) => {
// One notification per move: evaluate() publishes the position with the hint.
state = { ...state, x: e.clientX, y: e.clientY, alt: e.altKey }
state = { ...state, x: e.clientX, y: e.clientY, mod: hasMod(e) }
evaluate()
}
const onUp = () => finish(true)
@@ -206,8 +207,8 @@ export function beginDrag(payload: DragPayload, at: { x: number; y: number; alt:
finish(false)
return
}
if (e.key === 'Alt' && state.alt !== (e.type === 'keydown')) {
set({ alt: e.type === 'keydown' })
if (e.key === MOD_KEY && state.mod !== (e.type === 'keydown')) {
set({ mod: e.type === 'keydown' })
evaluate()
}
}
@@ -240,7 +241,7 @@ export function beginDrag(payload: DragPayload, at: { x: number; y: number; alt:
/** A drag the OS owns (files from Finder / Explorer): it enters the window… */
export function nativeDragStart(payload: DragPayload, at: { x: number; y: number }) {
const close = open(payload, { ...at, alt: false })
const close = open(payload, { ...at, mod: false })
detach = () => {
detach = null
close()
@@ -276,7 +277,7 @@ export function usePressToDrag(make: () => DragPayload | null): (e: React.Pointe
if (Math.hypot(m.clientX - start.x, m.clientY - start.y) < 6) return
stop()
const payload = makeRef.current()
if (payload) beginDrag(payload, { x: m.clientX, y: m.clientY, alt: m.altKey })
if (payload) beginDrag(payload, { x: m.clientX, y: m.clientY, mod: hasMod(m) })
}
const stop = () => {
window.removeEventListener('pointermove', onMove)
+15
View File
@@ -0,0 +1,15 @@
// The platform's command modifier: Cmd on macOS, Ctrl elsewhere. For mouse
// gestures it is exactly that key — on macOS, Ctrl+click is a right-click, so
// accepting either (as the keyboard shortcuts do) would start a drag under a
// context menu.
export const IS_MAC = /Mac|iPhone|iPad/.test(navigator.userAgent)
/** Whether the command modifier is held. */
export const hasMod = (e: { metaKey: boolean; ctrlKey: boolean }) => (IS_MAC ? e.metaKey : e.ctrlKey)
/** Its `KeyboardEvent.key`, for following it being pressed mid-gesture. */
export const MOD_KEY = IS_MAC ? 'Meta' : 'Control'
/** Its name in a tooltip ("Cmd-click"). */
export const MOD_NAME = IS_MAC ? 'Cmd' : 'Ctrl'
+14 -16
View File
@@ -2,21 +2,20 @@
// Written out BY HAND, not derived from the handlers: keep it in step with
// `PrepStrip` (deck), `TrackTable` (track list) and `SettingsMenu` (`?`).
import { cueTypeColor, GRID_MARKER_ACTIVE_COLOR } from './cues'
export const IS_MAC = /Mac|iPhone|iPad/.test(navigator.userAgent)
import { IS_MAC } from './modKey'
/** A modifier layer of the keyboard. `mod` is Cmd on macOS, Ctrl elsewhere —
* the handlers accept either, but the map names your key. */
export type Layer = 'base' | 'shift' | 'mod' | 'alt'
export const LAYERS: Layer[] = ['base', 'shift', 'mod', 'alt']
export type Layer = 'base' | 'shift' | 'mod'
export const LAYERS: Layer[] = ['base', 'shift', 'mod']
export const MODIFIER_KEY: Record<Exclude<Layer, 'base'>, string> = IS_MAC
? { shift: '⇧', mod: '⌘', alt: '⌥' }
: { shift: 'Shift', mod: 'Ctrl', alt: 'Alt' }
? { shift: '⇧', mod: '⌘' }
: { shift: 'Shift', mod: 'Ctrl' }
export const LAYER_NAMES: Record<Layer, string> = IS_MAC
? { base: 'No modifier', shift: '⇧ Shift', mod: '⌘ Command', alt: '⌥ Option' }
: { base: 'No modifier', shift: 'Shift', mod: 'Ctrl', alt: 'Alt' }
? { base: 'No modifier', shift: '⇧ Shift', mod: '⌘ Command' }
: { base: 'No modifier', shift: 'Shift', mod: 'Ctrl' }
/** Where a shortcut acts. The colour lights its key on the map. */
export type Area = 'deck' | 'list' | 'any'
@@ -62,7 +61,7 @@ export function padRange(slots: number): string {
}
export function bindings(slots: number): Bindings {
const b: Bindings = { base: {}, shift: {}, mod: {}, alt: {} }
const b: Bindings = { base: {}, shift: {}, mod: {} }
const pad = cueTypeColor('cue')
padCodes(slots).forEach((code, i) => {
const n = i + 1
@@ -142,7 +141,7 @@ export const MOUSE: { title: string; rows: MouseGesture[] }[] = [
{ gesture: 'Drag', on: 'waveform', text: 'Scratch' },
{ mod: 'mod', gesture: 'Scroll', on: 'waveform', text: 'Zoom in and out' },
{ gesture: 'Click', on: 'stem button', text: 'Mute or unmute that stem' },
{ mod: 'alt', gesture: 'Click', on: 'stem button', text: 'Solo that stem' },
{ mod: 'mod', gesture: 'Click', on: 'stem button', text: 'Solo that stem' },
{ gesture: 'Right-click', on: 'pad', text: 'Hotcue type, colour, rename, delete' },
],
},
@@ -155,7 +154,7 @@ export const MOUSE: { title: string; rows: MouseGesture[] }[] = [
{ gesture: 'Double-click', on: 'cell', text: 'Edit it in place' },
{ gesture: 'Right-click', text: 'Track menu. On the header: choose columns' },
{ gesture: 'Drag', on: 'rows', text: 'Onto a playlist or export to add, onto the deck to load, within a playlist to reorder' },
{ mod: 'alt', gesture: 'Drag', on: 'rows', text: 'Move them out of this playlist into another' },
{ mod: 'mod', gesture: 'Drag', on: 'rows', text: 'Move them out of this playlist into another' },
],
},
{
@@ -200,18 +199,18 @@ export const KEY_ROWS: KeyDef[][] = (() => {
? [
key('Fn', 'fn'),
key('ControlLeft', 'control', 1.25, undefined, 'ctrl'),
key('AltLeft', 'option ⌥', 1.25, 'alt', '⌥'),
key('AltLeft', 'option ⌥', 1.25, undefined, '⌥'),
key('MetaLeft', 'command ⌘', 1.5, 'mod', '⌘'),
key('Space', 'space', 6.75),
key('MetaRight', 'command ⌘', 1.5, 'mod', '⌘'),
key('AltRight', 'option ⌥', 1.25, 'alt', '⌥'),
key('AltRight', 'option ⌥', 1.25, undefined, '⌥'),
]
: [
key('ControlLeft', 'Ctrl', 1.25, 'mod'),
key('MetaLeft', 'Win', 1.25),
key('AltLeft', 'Alt', 1.25, 'alt'),
key('AltLeft', 'Alt', 1.25),
key('Space', 'space', 6.75),
key('AltRight', 'Alt', 1.25, 'alt'),
key('AltRight', 'Alt', 1.25),
key('MetaRight', 'Win', 1.25),
key('ControlRight', 'Ctrl', 1.5, 'mod'),
]
@@ -246,7 +245,6 @@ export const KEYS_BY_CODE: Record<string, KeyDef> = Object.fromEntries(
/** The modifier layer a physical key holds, if it is one. */
export function modifierLayer(code: string): Exclude<Layer, 'base'> | null {
if (code === 'ShiftLeft' || code === 'ShiftRight') return 'shift'
if (code === 'AltLeft' || code === 'AltRight') return 'alt'
const mod = IS_MAC ? ['MetaLeft', 'MetaRight'] : ['ControlLeft', 'ControlRight']
return mod.includes(code) ? 'mod' : null
}