X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/906790226701c99aede853b0ff46bd1998b40aa0..refs/pull/4193/head:/resources/js/components/shortcuts.js diff --git a/resources/js/components/shortcuts.js b/resources/js/components/shortcuts.js index cec8684c8..8e927e34c 100644 --- a/resources/js/components/shortcuts.js +++ b/resources/js/components/shortcuts.js @@ -1,3 +1,5 @@ +import {Component} from './component'; + function reverseMap(map) { const reversed = {}; for (const [key, value] of Object.entries(map)) { @@ -6,10 +8,7 @@ function reverseMap(map) { return reversed; } -/** - * @extends {Component} - */ -class Shortcuts { +export class Shortcuts extends Component { setup() { this.container = this.$el; @@ -25,7 +24,6 @@ class Shortcuts { setupListeners() { window.addEventListener('keydown', event => { - if (event.target.closest('input, select, textarea')) { return; } @@ -35,7 +33,8 @@ class Shortcuts { window.addEventListener('keydown', event => { if (event.key === '?') { - this.hintsShowing ? this.hideHints() : this.showHints(); + const action = this.hintsShowing ? this.hideHints : this.showHints; + action(); } }); } @@ -44,7 +43,6 @@ class Shortcuts { * @param {KeyboardEvent} event */ handleShortcutPress(event) { - const keys = [ event.ctrlKey ? 'Ctrl' : '', event.metaKey ? 'Cmd' : '', @@ -70,7 +68,6 @@ class Shortcuts { */ runShortcut(id) { const el = this.container.querySelector(`[data-shortcut="${id}"]`); - console.info('Shortcut run', el); if (!el) { return false; } @@ -91,7 +88,7 @@ class Shortcuts { return true; } - console.error(`Shortcut attempted to be ran for element type that does not have handling setup`, el); + console.error('Shortcut attempted to be ran for element type that does not have handling setup', el); return false; } @@ -136,10 +133,10 @@ class Shortcuts { const linkage = document.createElement('div'); linkage.classList.add('shortcut-linkage'); - linkage.style.left = targetBounds.x + 'px'; - linkage.style.top = targetBounds.y + 'px'; - linkage.style.width = targetBounds.width + 'px'; - linkage.style.height = targetBounds.height + 'px'; + linkage.style.left = `${targetBounds.x}px`; + linkage.style.top = `${targetBounds.y}px`; + linkage.style.width = `${targetBounds.width}px`; + linkage.style.height = `${targetBounds.height}px`; wrapper.append(label, linkage); @@ -160,6 +157,5 @@ class Shortcuts { this.hintsShowing = false; } -} -export default Shortcuts; \ No newline at end of file +}