mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-10-01 07:49:12 -04:00
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.
This commit is contained in:
+7
-9
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user