mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
42 lines
747 B
JavaScript
42 lines
747 B
JavaScript
|
const cache = {};
|
||
|
|
||
|
export function includes(event) {
|
||
|
const keys = [];
|
||
|
let ctrlPressed = false;
|
||
|
|
||
|
if (event.ctrlKey) {
|
||
|
keys.push('ctrl');
|
||
|
ctrlPressed = true;
|
||
|
}
|
||
|
|
||
|
if (event.shiftKey) {
|
||
|
keys.push('shift');
|
||
|
}
|
||
|
|
||
|
if (event.altKey) {
|
||
|
keys.push('alt');
|
||
|
}
|
||
|
|
||
|
keys.push(event.key);
|
||
|
|
||
|
const exists = cache[keys.join('+')];
|
||
|
|
||
|
if (!exists && ctrlPressed) { // Test things like cmd+s
|
||
|
return cache[keys.join('+').replace('ctrl', 'cmd')];
|
||
|
}
|
||
|
|
||
|
return exists;
|
||
|
}
|
||
|
|
||
|
export function register(shortcut) {
|
||
|
cache[shortcut.toLowerCase()] = true;
|
||
|
}
|
||
|
|
||
|
export function unregister(shortcut) {
|
||
|
delete cache[shortcut];
|
||
|
}
|
||
|
|
||
|
export function getAll() {
|
||
|
return Object.assign({}, cache);
|
||
|
}
|