Enhance shortcut navigation and add replacement acceptance logic for mistakes #4

This commit is contained in:
Aljaž Grilc 2025-06-04 15:03:10 +02:00
parent e903917179
commit 1163b3c47e

View File

@ -336,6 +336,7 @@ class BesService {
* @param {Event} e * @param {Event} e
*/ */
onShortcutNavigation(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 if (!this.highlightElements.length) return
switch (e.code) { switch (e.code) {
case 'BracketLeft': case 'BracketLeft':
@ -358,9 +359,10 @@ class BesService {
if (e.ctrlKey) { if (e.ctrlKey) {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
// TODO: What to do when we have multiple replacements?
this.acceptReplacement() this.acceptReplacement()
} }
case 'Escape':
this.dismissPopup()
default: default:
break 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 * Clears highlight and hides popup
*/ */