X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/66c8809799611a729a39b7d31d7b1e41f286201c..refs/pull/3830/head:/resources/js/components/shortcuts.js diff --git a/resources/js/components/shortcuts.js b/resources/js/components/shortcuts.js index ccad00f5d..4efa3d42b 100644 --- a/resources/js/components/shortcuts.js +++ b/resources/js/components/shortcuts.js @@ -30,13 +30,7 @@ class Shortcuts { return; } - const shortcutId = this.mapByShortcut[event.key]; - if (shortcutId) { - const wasHandled = this.runShortcut(shortcutId); - if (wasHandled) { - event.preventDefault(); - } - } + this.handleShortcutPress(event); }); window.addEventListener('keydown', event => { @@ -46,6 +40,28 @@ class Shortcuts { }); } + /** + * @param {KeyboardEvent} event + */ + handleShortcutPress(event) { + + const keys = [ + event.ctrlKey ? 'Ctrl' : '', + event.metaKey ? 'Cmd' : '', + event.key, + ]; + + const combo = keys.filter(s => Boolean(s)).join(' + '); + + const shortcutId = this.mapByShortcut[combo]; + if (shortcutId) { + const wasHandled = this.runShortcut(shortcutId); + if (wasHandled) { + event.preventDefault(); + } + } + } + /** * Run the given shortcut, and return a boolean to indicate if the event * was successfully handled by a shortcut action. @@ -54,7 +70,6 @@ class Shortcuts { */ runShortcut(id) { const el = this.container.querySelector(`[data-shortcut="${id}"]`); - console.info('Shortcut run', el); if (!el) { return false; }