From 04cd5f2e7dc99934edd1d2c0f24423c6a1fdce58 Mon Sep 17 00:00:00 2001 From: Aljaz Grilc Date: Thu, 5 Jun 2025 08:11:42 +0200 Subject: [PATCH] Use scrollintoView after using shortcut navigation for finding a next/previous mistake #4 --- service.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/service.js b/service.js index eaecf00..53d8229 100644 --- a/service.js +++ b/service.js @@ -336,8 +336,6 @@ 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': if (e.ctrlKey) { @@ -1195,16 +1193,19 @@ class BesService { this.activeMatchIndex = next const { el, match } = this.sortedMatches[next] - // TODO: find out why scrollintoview does not work well - this.dismissPopup() - const popup = document.querySelector('bes-popup-el') - BesPopup.clearReplacements() - popup.setContent(el, match, this, this.isContentEditable()) - this.highlightMistake(match) - match.highlights.forEach(el => { - const clientY = `${el.y + 150}` - popup.show(el.x, clientY, this) - }) + // Not the cleanest solution, but it is good enough for now + el.scrollIntoView({ behavior: 'instant' }) + setTimeout(() => { + this.dismissPopup() + const popup = document.querySelector('bes-popup-el') + BesPopup.clearReplacements() + popup.setContent(el, match, this, this.isContentEditable()) + this.highlightMistake(match) + match.highlights.forEach(el => { + const clientY = `${el.y + 150}` + popup.show(el.x, clientY, this) + }) + }, 150) } /**