From a6086db046840c70b090c08048638a41673be053 Mon Sep 17 00:00:00 2001 From: katspaugh <381895+katspaugh@users.noreply.github.com> Date: Sun, 3 Dec 2023 11:30:31 +0100 Subject: [PATCH] Fix: [Regions] improve overlapping content (#3373) * Fix: [Regions] improve overlapping content * Refactor --- src/plugins/regions.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/plugins/regions.ts b/src/plugins/regions.ts index 6fc47faa6..917b647ca 100644 --- a/src/plugins/regions.ts +++ b/src/plugins/regions.ts @@ -294,6 +294,7 @@ class SingleRegion extends EventEmitter { this.content = document.createElement('div') const isMarker = this.start === this.end this.content.style.padding = `0.2em ${isMarker ? 0.2 : 0.4}em` + this.content.style.display = 'inline-block' this.content.textContent = content } else { this.content = content @@ -428,17 +429,18 @@ class RegionsPlugin extends BasePlugin { - if (reg === region || !reg.content) return false - const left = reg.content.getBoundingClientRect().left - const width = reg.element.scrollWidth - return labelLeft < left + width && left < labelLeft + labelWidth + .map((reg) => { + if (reg === region || !reg.content) return 0 + + const otherBox = reg.content.getBoundingClientRect() + if (box.left < otherBox.left + otherBox.width && otherBox.left < box.left + box.width) { + return otherBox.height + } + return 0 }) - .map((reg) => reg.content?.getBoundingClientRect().height || 0) .reduce((sum, val) => sum + val, 0) div.style.marginTop = `${overlap}px`