export const mac = /Mac|iPhone|iPad/.test(navigator.platform); /** How the platform's command key reads next to a letter: ⌘K or Ctrl K. */ export function shortcut(key: string): string { return mac ? `⌘${key}` : `Ctrl ${key}`; } /** The command key by itself, as a chip in a hint: ⌘ or Ctrl. */ export const command = mac ? '⌘' : 'Ctrl'; /** How the platform's option key reads, alone or beside a key: ⌥G or Alt G. */ export function option(key = ''): string { return mac ? `⌥${key}` : `Alt${key && ` ${key}`}`; } /** The palette opened for commands only, as VS Code's. */ export const commandsKey = mac ? '⇧⌘P' : 'Ctrl Shift P'; /** Redo, the other half of `shortcut('Z')`. */ export const redo = mac ? '⇧⌘Z' : 'Ctrl Y'; /** * The canvas's gestures and keys, for the keys pane and the canvas's view * bar (which shows only what nothing on screen does): `where` limits one to * the bar or to the pane. */ export const canvasKeys: { keys: string[]; does: string; where?: 'bar' | 'pane' }[] = [ { keys: ['spc', 'grab'], does: 'pan' }, { keys: [option(), 'move'], does: 'move window' }, { keys: [command, 'scroll'], does: 'zoom' }, { keys: [option(), 'scroll'], does: 'window zoom' }, { keys: ['+', '−'], does: 'zoom in, out', where: 'pane' }, { keys: ['⇧1'], does: 'fit all' }, { keys: ['⇧0'], does: 'zoom to 100%', where: 'pane' }, { keys: ['M'], does: 'overview map', where: 'pane' }, { keys: [option('←→↑↓')], does: 'windows', where: 'bar' }, { keys: ['S'], does: 'new session', where: 'bar' }, { keys: ['T'], does: 'terminal', where: 'bar' }, { keys: ['spc', 'click', 'click'], does: 'zoom at' }, { keys: ['click', 'click'], does: 'note' }, ]; /** Whether a key press belongs to a text field rather than to the app. */ export function typing(event: KeyboardEvent): boolean { const target = event.target as HTMLElement | null; return !!target && (target.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(target.tagName)); }