mirror of
https://github.com/mmjee/Piped-Material.git
synced 2024-12-06 19:26:36 +01:00
20 lines
573 B
JavaScript
20 lines
573 B
JavaScript
import tinykeys from 'tinykeys'
|
|
|
|
export function setupKeybindings (el, bindings, ...extra) {
|
|
const newBindings = {}
|
|
for (const [k, f] of Object.entries(bindings)) {
|
|
newBindings[k] = (ev, ...args) => {
|
|
const active = ev.target
|
|
const enteringText = active instanceof HTMLElement &&
|
|
(active.isContentEditable ||
|
|
active.tagName === 'INPUT' ||
|
|
active.tagName === 'TEXTAREA' ||
|
|
active.tagName === 'SELECT'
|
|
)
|
|
if (!enteringText) return f(ev, ...args)
|
|
}
|
|
}
|
|
|
|
return tinykeys(el, newBindings, ...extra)
|
|
}
|