diff --git a/service.js b/service.js index dab0959..eaecf00 100644 --- a/service.js +++ b/service.js @@ -336,6 +336,7 @@ class BesService { * @param {Event} e */ onShortcutNavigation(e) { + //TODO: If no highlightElement is selected? find the first mistake that comes after cursor and move to it. if (!this.highlightElements.length) return switch (e.code) { case 'BracketLeft': @@ -358,9 +359,10 @@ class BesService { if (e.ctrlKey) { e.preventDefault() e.stopPropagation() - // TODO: What to do when we have multiple replacements? this.acceptReplacement() } + case 'Escape': + this.dismissPopup() default: break } @@ -1205,6 +1207,23 @@ class BesService { }) } + /** + * Accepts the replacement for the current grammar mistake. + */ + acceptReplacement() { + const popup = document.querySelector('bes-popup-el') + const replacementDiv = popup.shadowRoot.querySelector( + '.bes-replacement-div' + ) + const firstReplacement = replacementDiv?.firstChild + if (replacementDiv.childElementCount === 1) { + // Is this an ugly solution? + firstReplacement.click() + } else if (replacementDiv.childElementCount > 1) { + firstReplacement.focus() + } else this.findNextMistake(1) + } + /** * Clears highlight and hides popup */