mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-20 13:48:09 +00:00
[Glitch] refactor: Replace react-hotkeys with custom hook
Port 4de5cbd6f5 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
29
app/javascript/flavours/glitch/components/hotkeys/utils.ts
Normal file
29
app/javascript/flavours/glitch/components/hotkeys/utils.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export function isKeyboardEvent(event: Event): event is KeyboardEvent {
|
||||
return 'key' in event;
|
||||
}
|
||||
|
||||
export function normalizeKey(key: string): string {
|
||||
const lowerKey = key.toLowerCase();
|
||||
|
||||
switch (lowerKey) {
|
||||
case ' ':
|
||||
case 'spacebar': // for older browsers
|
||||
return 'space';
|
||||
|
||||
case 'arrowup':
|
||||
return 'up';
|
||||
case 'arrowdown':
|
||||
return 'down';
|
||||
case 'arrowleft':
|
||||
return 'left';
|
||||
case 'arrowright':
|
||||
return 'right';
|
||||
|
||||
case 'esc':
|
||||
case 'escape':
|
||||
return 'escape';
|
||||
|
||||
default:
|
||||
return lowerKey;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user