From 5102fc70ddf1c5f999ac015d3044d7c88840a0a1 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sun, 13 Sep 2026 18:23:52 -0400 Subject: [PATCH] Clamp by geometry, not the visible range The last visible range can extend past the visible column on text nodes that span multiple columns (its end-offset bisect uses union rects), so comparing DOM boundary points against it misses off-view selection endpoints. Test the endpoint caret rect against the visible column bounds instead. --- paginator.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/paginator.js b/paginator.js index 361b1e0..fab3d21 100644 --- a/paginator.js +++ b/paginator.js @@ -960,20 +960,18 @@ export class Paginator extends HTMLElement { this.start - size, this.end - size, this.#getRectMapper()) } #clampTouchSelection(sel, doc) { - const range = this.#lastVisibleRange - if (!range || !sel.rangeCount) return + if (!sel.rangeCount) return const backward = selectionIsBackward(sel) const probe = sel.getRangeAt(0).cloneRange() probe.collapse(!backward) - if (backward - ? range.compareBoundaryPoints(Range.START_TO_START, probe) <= 0 - : range.compareBoundaryPoints(Range.END_TO_END, probe) >= 0) return const rect = probe.getBoundingClientRect() - if (!rect) return + if (!rect || (rect.width === 0 && rect.height === 0 && !rect.x && !rect.y)) + return const size = this.#rtl ? -this.size : this.size - const x = backward - ? this.start - size + 1 - : this.end - size - 1 + const left = this.start - size + const right = this.end - size + if (backward ? rect.left >= left : rect.left <= right) return + const x = backward ? left + 1 : right - 1 const caret = doc.caretRangeFromPoint?.(x, rect.top) ?? doc.caretPositionFromPoint?.(x, rect.top) if (!caret) return