From 3cd86bf4c3237a073a8beb801c4376cd1bf2f22c Mon Sep 17 00:00:00 2001 From: Aljaz Grilc Date: Mon, 9 Jun 2025 11:48:15 +0200 Subject: [PATCH] Fix scrollIntoView behavior and improve popup positioning #4 --- service.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/service.js b/service.js index 0b7ea1e..35eeae5 100644 --- a/service.js +++ b/service.js @@ -1200,17 +1200,25 @@ class BesService { service.activeMatchIndex = next const { el, match } = service.sortedMatches[next] - // Not the cleanest solution, but it is good enough for now - el.scrollIntoView({ behavior: 'instant' }) + if (el && typeof el.scrollIntoView === 'function') { + el.scrollIntoView({ behavior: 'instant', block: 'center' }) + } + // Not the cleanest solution to setTimeout() setTimeout(() => { service.dismissPopup() const popup = document.querySelector('bes-popup-el') BesPopup.clearReplacements() popup.setContent(el, match, service, service.isContentEditable()) service.highlightMistake(match) - match.highlights.forEach(el => { - const clientY = `${el.y + 150}` - popup.show(el.x, clientY, service) + const containerRect = service.hostElement.getBoundingClientRect() + match.highlights.forEach(rect => { + const clientX = rect.x + containerRect.left + const clientY = + rect.y + + containerRect.top + + rect.height - + service.hostElement.scrollTop + popup.show(clientX, clientY, service) }) }, 150) }