From 2a54b52fdb8ed98f9ae57a52ab8aa74f8f1ba755 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sun, 13 Sep 2026 18:18:03 -0400 Subject: [PATCH] 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. --- paginator.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/paginator.js b/paginator.js index 21326fd..361b1e0 100644 --- a/paginator.js +++ b/paginator.js @@ -603,6 +603,7 @@ export class Paginator extends HTMLElement { doc.addEventListener('pointerdown', e => { touchSelecting = e.pointerType === 'touch' }) + doc.addEventListener('keydown', () => touchSelecting = false) let isKeyboardSelecting = false doc.addEventListener('keydown', () => isKeyboardSelecting = true) doc.addEventListener('keyup', () => isKeyboardSelecting = false) @@ -612,11 +613,8 @@ export class Paginator extends HTMLElement { if (!range) return const sel = doc.getSelection() if (!sel.rangeCount) return - if (touchSelecting) { - if (sel.isCollapsed) touchSelecting = false - else if (sel.type === 'Range') - this.#clampTouchSelection(sel, doc) - } + if (touchSelecting && sel.type === 'Range') + this.#clampTouchSelection(sel, doc) if (isPointerSelecting && sel.type === 'Range') checkPointerSelection(range, sel) else if (isKeyboardSelecting) {