Keep touchSelecting armed through collapsed selectionchange events

Chrome emits collapsed selectionchange events while the long-press
word selection is being set up; clearing the flag on them disarmed
the clamp before the selection ever became a Range.
This commit is contained in:
John O'Keefe
2026-09-13 18:18:03 -04:00
parent 8ac36efbda
commit 2a54b52fdb
+2 -4
View File
@@ -603,6 +603,7 @@ export class Paginator extends HTMLElement {
doc.addEventListener('pointerdown', e => { doc.addEventListener('pointerdown', e => {
touchSelecting = e.pointerType === 'touch' touchSelecting = e.pointerType === 'touch'
}) })
doc.addEventListener('keydown', () => touchSelecting = false)
let isKeyboardSelecting = false let isKeyboardSelecting = false
doc.addEventListener('keydown', () => isKeyboardSelecting = true) doc.addEventListener('keydown', () => isKeyboardSelecting = true)
doc.addEventListener('keyup', () => isKeyboardSelecting = false) doc.addEventListener('keyup', () => isKeyboardSelecting = false)
@@ -612,11 +613,8 @@ export class Paginator extends HTMLElement {
if (!range) return if (!range) return
const sel = doc.getSelection() const sel = doc.getSelection()
if (!sel.rangeCount) return if (!sel.rangeCount) return
if (touchSelecting) { if (touchSelecting && sel.type === 'Range')
if (sel.isCollapsed) touchSelecting = false
else if (sel.type === 'Range')
this.#clampTouchSelection(sel, doc) this.#clampTouchSelection(sel, doc)
}
if (isPointerSelecting && sel.type === 'Range') if (isPointerSelecting && sel.type === 'Range')
checkPointerSelection(range, sel) checkPointerSelection(range, sel)
else if (isKeyboardSelecting) { else if (isKeyboardSelecting) {