Ghost/ghost/admin/app/utils/shortcuts.js
Kukhyeon Heo 3780e80b14 🐛 Fixed pasting into the post tags input not working (#1739)
closes https://github.com/tryghost/ghost/issues/12294
refs https://github.com/TryGhost/Admin/pull/1707

- cache registered shortcuts and check KeyboardEvent before dispatching event to the root
2022-08-03 11:14:12 +01:00

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);
}