GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stacki/src/lib/shortcutLabel.ts at main · flowtricks/stacki

Expand file tree

/

shortcutLabel.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
61 lines (54 loc) · 2.59 KB
/

shortcutLabel.ts

Copy path

File metadata and controls

61 lines (54 loc) · 2.59 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
type ShortcutModifier = 'primary' | 'primary-shift';
export function currentDesktopPlatform(): NodeJS.Platform {
if (typeof window === 'undefined') {
return 'linux';
}
return window.avb?.platform ?? (/Mac|iPhone|iPad/.test(navigator.platform) ? 'darwin' : /Win/.test(navigator.platform) ? 'win32' : 'linux');
}
export function shortcutLabel(key: string, modifier: ShortcutModifier, platform: NodeJS.Platform): string {
if (platform === 'darwin') {
return modifier === 'primary-shift' ? `⌘⇧${key}` : `⌘${key}`;
}
return modifier === 'primary-shift' ? `Ctrl+Shift+${key}` : `Ctrl+${key}`;
}
// The modifier glyphs a Mac label is written with, as the names `aria-keyshortcuts` expects.
const GLYPH_MODIFIERS: Readonly<Record<string, string>> = { '⌘': 'Meta', '⌥': 'Alt', '⌃': 'Control', '⇧': 'Shift' };
const GLYPH_KEYS: Readonly<Record<string, string>> = { '⌫': 'Backspace' };
const WORD_KEYS: Readonly<Record<string, string>> = { Ctrl: 'Control', Del: 'Delete' };
/**
* A shortcut as shown ("⌥E", "⌘⇧D", "Ctrl+C", "⌫") in the form `aria-keyshortcuts` takes ("Alt+E", "Meta+Shift+D", "Control+C",
* "Backspace"). Why: a screen reader cannot be told to announce a glyph, and the tooltip that shows the glyph is hidden from it,
* so the element itself must carry the chord in the standard names.
*/
export function ariaKeyShortcuts(display: string): string {
const parts: string[] = [];
let rest = display;
// A chord has a handful of modifiers; the bound keeps a malformed label from looping.
for (let guard = 0; guard < 8; guard += 1) {
const modifier = GLYPH_MODIFIERS[rest.charAt(0)];
if (modifier === undefined) {
break;
}
parts.push(modifier);
rest = rest.slice(1);
}
const tail = rest
.split('+')
.map((word) => WORD_KEYS[word] ?? GLYPH_KEYS[word] ?? word)
.filter((word) => word.length > 0);
return [...parts, ...tail].join('+');
}
// "Add to chat": ⌘L on a Mac, Ctrl+L elsewhere. Nothing else in the app takes it (the application menu has no L,
// and the code editor's line select is Ctrl+L on a Mac and Alt+L elsewhere, both left alone here).
/** The parts of a key event the shortcut is read from. */
export interface AddToChatKeyEvent {
readonly key: string;
readonly metaKey: boolean;
readonly ctrlKey: boolean;
readonly shiftKey: boolean;
readonly altKey: boolean;
}
export function isAddToChatKey(event: AddToChatKeyEvent, platform: NodeJS.Platform): boolean {
const primary = platform === 'darwin' ? event.metaKey : event.ctrlKey;
return primary && !event.shiftKey && !event.altKey && event.key.toLowerCase() === 'l';
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.