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
*/
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
*/