@arbidocs/react 0.4.56 → 0.4.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -501,6 +501,9 @@ function readSelection(selection, root = document) {
|
|
|
501
501
|
// src/annotations/useTextSelectionMarks.ts
|
|
502
502
|
var PAGE_SELECTOR = "[data-page-number]";
|
|
503
503
|
var TOUCH_SETTLE_MS = 700;
|
|
504
|
+
var MOUSE_SETTLE_MS = 60;
|
|
505
|
+
var STABLE_CHECKS = 2;
|
|
506
|
+
var MAX_SETTLE_ROUNDS = 10;
|
|
504
507
|
function useTextSelectionMarks(controller) {
|
|
505
508
|
const latest = useRef(controller);
|
|
506
509
|
latest.current = controller;
|
|
@@ -508,6 +511,7 @@ function useTextSelectionMarks(controller) {
|
|
|
508
511
|
let startedOnPage = false;
|
|
509
512
|
let touchSelecting = false;
|
|
510
513
|
let settleTimer;
|
|
514
|
+
const settleTimers = /* @__PURE__ */ new Set();
|
|
511
515
|
const markSelection = () => {
|
|
512
516
|
const c = latest.current;
|
|
513
517
|
const selection = window.getSelection();
|
|
@@ -541,9 +545,23 @@ function useTextSelectionMarks(controller) {
|
|
|
541
545
|
const onUp = () => {
|
|
542
546
|
if (!startedOnPage || !TEXT_TOOLS.includes(latest.current.tool)) return;
|
|
543
547
|
startedOnPage = false;
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
548
|
+
let last = window.getSelection()?.toString() ?? "";
|
|
549
|
+
let stable = 0;
|
|
550
|
+
let rounds = 0;
|
|
551
|
+
const check = () => {
|
|
552
|
+
const now = window.getSelection()?.toString() ?? "";
|
|
553
|
+
if (now === last) stable++;
|
|
554
|
+
else {
|
|
555
|
+
last = now;
|
|
556
|
+
stable = 0;
|
|
557
|
+
}
|
|
558
|
+
if (stable >= STABLE_CHECKS || ++rounds >= MAX_SETTLE_ROUNDS) {
|
|
559
|
+
if (markSelection()) touchSelecting = false;
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
settleTimers.add(setTimeout(check, MOUSE_SETTLE_MS));
|
|
563
|
+
};
|
|
564
|
+
settleTimers.add(setTimeout(check, MOUSE_SETTLE_MS));
|
|
547
565
|
};
|
|
548
566
|
const onSelectionChange = () => {
|
|
549
567
|
if (!touchSelecting || !TEXT_TOOLS.includes(latest.current.tool)) return;
|
|
@@ -557,6 +575,7 @@ function useTextSelectionMarks(controller) {
|
|
|
557
575
|
document.addEventListener("selectionchange", onSelectionChange);
|
|
558
576
|
return () => {
|
|
559
577
|
clearTimeout(settleTimer);
|
|
578
|
+
settleTimers.forEach(clearTimeout);
|
|
560
579
|
document.removeEventListener("pointerdown", onDown, true);
|
|
561
580
|
document.removeEventListener("pointerup", onUp, true);
|
|
562
581
|
document.removeEventListener("selectionchange", onSelectionChange);
|