From 29e83ccc0aee3a71784681abca8ebb625bcdb4c4 Mon Sep 17 00:00:00 2001 From: Aljaz Grilc Date: Wed, 26 Feb 2025 09:28:33 +0100 Subject: [PATCH] Prevent endless loop when zooming in/out and dismiss popup on scroll event --- service.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/service.js b/service.js index 5f312ba..6053354 100644 --- a/service.js +++ b/service.js @@ -274,10 +274,31 @@ class BesService { this.eventSink.endProofing(this) } + /** + * Temporarily disables the mutation observer. + */ + disableMutationObserver() { + if (this.mutationObserver) this.mutationObserver.disconnect() + } + + /** + * Re-enables the mutation observer. + */ + enableMutationObserver() { + if (this.mutationObserver) { + this.mutationObserver.observe(document.body, { + attributes: true, + childList: true, + subtree: true + }) + } + } + /** * Called to report scrolling */ onScroll() { + this.dismissPopup() // Scroll panel is "position: absolute", we need to keep it aligned with the host element. this.scrollPanel.style.top = `${-this.hostElement.scrollTop}px` this.scrollPanel.style.left = `${-this.hostElement.scrollLeft}px` @@ -409,6 +430,7 @@ class BesService { * Resizes correction and scroll panels to match host element size. */ setCorrectionPanelSize() { + this.disableMutationObserver() const styles = window.getComputedStyle(this.hostElement) this.correctionPanel.style.marginLeft = styles.marginLeft this.correctionPanel.style.marginTop = styles.marginTop @@ -445,6 +467,7 @@ class BesService { this.correctionPanel.style.width = styles.width this.correctionPanel.style.height = styles.height } + this.enableMutationObserver() } /**