forked from github/hotkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
28 lines (24 loc) · 782 Bytes
/
utils.js
File metadata and controls
28 lines (24 loc) · 782 Bytes
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
/* @flow strict */
export function isFormField(element: Node): boolean {
if (!(element instanceof HTMLElement)) {
return false
}
const name = element.nodeName.toLowerCase()
const type = (element.getAttribute('type') || '').toLowerCase()
return (
name === 'select' ||
name === 'textarea' ||
(name === 'input' && type !== 'submit' && type !== 'reset') ||
element.isContentEditable
)
}
export function fireDeterminedAction(el: HTMLElement): void {
if (isFormField(el)) {
el.focus()
} else if ((el instanceof HTMLAnchorElement && el.href) || el.tagName === 'BUTTON' || el.tagName === 'SUMMARY') {
el.click()
}
}
export function expandHotkeyToEdges(hotkey: string): string[][] {
return hotkey.split(',').map(edge => edge.split(' '))
}