From 15118841376bd0f6555b3f3fbc6b1bd16169afd7 Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Mon, 20 Mar 2023 00:31:10 +0800 Subject: [PATCH] Fix scrolling to range following auto hyphen in different column --- paginator.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/paginator.js b/paginator.js index aa5405b..af84bcf 100644 --- a/paginator.js +++ b/paginator.js @@ -573,9 +573,13 @@ export class Paginator { return this.#scrollTo(offset, reason) } async #scrollToAnchor(select) { - const rect = uncollapse(this.#anchor).getBoundingClientRect?.() + const rects = uncollapse(this.#anchor)?.getClientRects() // if anchor is an element or a range - if (rect) { + if (rects) { + // when the start of the range is immediately after a hyphen in the + // previous column, there is an extra zero width rect in that column + const rect = Array.from(rects) + .find(r => r.width > 0 && r.height > 0) || rects[0] await this.#scrollToRect(rect, 'anchor') if (select) this.#selectAnchor() return