Don't classify selection-extension drags as swipe/pan

The gesture classifier only checked whether the touch STARTED on a
.textLayer span. Chromium's long-press selects the nearest word even
when the finger landed between spans (on the .textLayer div, not a
span inside it), so the classifier saw a non-selectable target and
classified the drag as swipe/pan — preventDefault on the iframe's
touchmove then cancelled the native selection extension mid-drag
and could blank the PDF canvas. If any frame already has a
non-collapsed selection, the drag is extending it.
This commit is contained in:
John O'Keefe
2026-09-16 10:40:24 -04:00
parent 8a203996ef
commit 94bb38453d
+13
View File
@@ -686,6 +686,19 @@ export class FixedLayout extends HTMLElement {
st.mode = "native"; // let the text layer handle selection st.mode = "native"; // let the text layer handle selection
return; return;
} }
// The long-press may have already engaged a native selection
// (Chromium selects the nearest word even when the finger
// landed between spans) — a drag with a live selection is
// extending it regardless of where the finger started.
// Classifying it as swipe/pan would preventDefault the
// touchmove and cancel the selection mid-drag.
for (const { doc } of this.getContents()) {
const sel = doc?.getSelection?.();
if (sel && !sel.isCollapsed) {
st.mode = "native";
return;
}
}
if (this.#atFitScale()) { if (this.#atFitScale()) {
st.mode = "swipe"; // page-turn gesture st.mode = "swipe"; // page-turn gesture
} else { } else {