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

+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
}