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