diff --git a/service.js b/service.js index 670e27e..91f733f 100644 --- a/service.js +++ b/service.js @@ -60,11 +60,11 @@ class BesService { this.hostElement.setAttribute('data-gramm', 'false') this.hostElement.setAttribute('data-gramm_editor', 'false') this.hostElement.setAttribute('data-enable-grammarly', 'false') - this.onTab = this.onTab.bind(this) - this.hostElement.addEventListener('keydown', this.onTab) this.onScroll = this.onScroll.bind(this) this.hostElement.addEventListener('scroll', this.onScroll) + this.onShortcutNavigation = this.onShortcutNavigation.bind(this) + this.hostElement.addEventListener('keydown', this.onShortcutNavigation) this.hostBoundingClientRect = this.hostElement.getBoundingClientRect() this.mutationObserver = new MutationObserver(this.onBodyMutate.bind(this)) @@ -111,6 +111,7 @@ class BesService { if (this.abortController) this.abortController.abort() besServices = besServices.filter(item => item !== this) this.mutationObserver.disconnect() + this.hostElement.removeEventListener('keydown', this.onShortcutNavigation) this.hostElement.removeEventListener('scroll', this.onScroll) this.hostElement.setAttribute('spellcheck', this.originalSpellcheck) this.hostElement.setAttribute('data-gramm', this.originalDataGramm) @@ -334,11 +335,27 @@ class BesService { * * @param {Event} e */ - onTab(e) { - if (e.key === 'Tab' && this.highlightElements.length) { - e.preventDefault() - e.stopPropagation() - this.findNextMistake(e.shiftKey ? -1 : 1) + onShortcutNavigation(e) { + if (!this.highlightElements.length) return + switch (e.code) { + case 'BracketLeft': + if (e.ctrlKey) { + // Handle Ctrl + [ OR Ctrl + Š + e.preventDefault() + e.stopPropagation() + this.findNextMistake(-1) + } + break + case 'BracketRight': + if (e.ctrlKey) { + // Handle Ctrl + ] OR Ctrl + Đ + e.preventDefault() + e.stopPropagation() + this.findNextMistake(1) + } + break + default: + break } }