mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-30 23:49:10 -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())
|
this.start - size, this.end - size, this.#getRectMapper())
|
||||||
}
|
}
|
||||||
#clampTouchSelection(sel, doc) {
|
#clampTouchSelection(sel, doc) {
|
||||||
const range = this.#lastVisibleRange
|
if (!sel.rangeCount) return
|
||||||
if (!range || !sel.rangeCount) return
|
|
||||||
const backward = selectionIsBackward(sel)
|
const backward = selectionIsBackward(sel)
|
||||||
const probe = sel.getRangeAt(0).cloneRange()
|
const probe = sel.getRangeAt(0).cloneRange()
|
||||||
probe.collapse(!backward)
|
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()
|
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 size = this.#rtl ? -this.size : this.size
|
||||||
const x = backward
|
const left = this.start - size
|
||||||
? this.start - size + 1
|
const right = this.end - size
|
||||||
: this.end - size - 1
|
if (backward ? rect.left >= left : rect.left <= right) return
|
||||||
|
const x = backward ? left + 1 : right - 1
|
||||||
const caret = doc.caretRangeFromPoint?.(x, rect.top)
|
const caret = doc.caretRangeFromPoint?.(x, rect.top)
|
||||||
?? doc.caretPositionFromPoint?.(x, rect.top)
|
?? doc.caretPositionFromPoint?.(x, rect.top)
|
||||||
if (!caret) return
|
if (!caret) return
|
||||||
|
|||||||
Reference in New Issue
Block a user