@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.
|
@@ -502,6 +502,9 @@ function readSelection(selection, root = document) {
|
|
|
502
502
|
// src/annotations/useTextSelectionMarks.ts
|
|
503
503
|
var PAGE_SELECTOR = "[data-page-number]";
|
|
504
504
|
var TOUCH_SETTLE_MS = 700;
|
|
505
|
+
var MOUSE_SETTLE_MS = 60;
|
|
506
|
+
var STABLE_CHECKS = 2;
|
|
507
|
+
var MAX_SETTLE_ROUNDS = 10;
|
|
505
508
|
function useTextSelectionMarks(controller) {
|
|
506
509
|
const latest = react.useRef(controller);
|
|
507
510
|
latest.current = controller;
|
|
@@ -509,6 +512,7 @@ function useTextSelectionMarks(controller) {
|
|
|
509
512
|
let startedOnPage = false;
|
|
510
513
|
let touchSelecting = false;
|
|
511
514
|
let settleTimer;
|
|
515
|
+
const settleTimers = /* @__PURE__ */ new Set();
|
|
512
516
|
const markSelection = () => {
|
|
513
517
|
const c = latest.current;
|
|
514
518
|
const selection = window.getSelection();
|
|
@@ -542,9 +546,23 @@ function useTextSelectionMarks(controller) {
|
|
|
542
546
|
const onUp = () => {
|
|
543
547
|
if (!startedOnPage || !TEXT_TOOLS.includes(latest.current.tool)) return;
|
|
544
548
|
startedOnPage = false;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
549
|
+
let last = window.getSelection()?.toString() ?? "";
|
|
550
|
+
let stable = 0;
|
|
551
|
+
let rounds = 0;
|
|
552
|
+
const check = () => {
|
|
553
|
+
const now = window.getSelection()?.toString() ?? "";
|
|
554
|
+
if (now === last) stable++;
|
|
555
|
+
else {
|
|
556
|
+
last = now;
|
|
557
|
+
stable = 0;
|
|
558
|
+
}
|
|
559
|
+
if (stable >= STABLE_CHECKS || ++rounds >= MAX_SETTLE_ROUNDS) {
|
|
560
|
+
if (markSelection()) touchSelecting = false;
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
settleTimers.add(setTimeout(check, MOUSE_SETTLE_MS));
|
|
564
|
+
};
|
|
565
|
+
settleTimers.add(setTimeout(check, MOUSE_SETTLE_MS));
|
|
548
566
|
};
|
|
549
567
|
const onSelectionChange = () => {
|
|
550
568
|
if (!touchSelecting || !TEXT_TOOLS.includes(latest.current.tool)) return;
|
|
@@ -558,6 +576,7 @@ function useTextSelectionMarks(controller) {
|
|
|
558
576
|
document.addEventListener("selectionchange", onSelectionChange);
|
|
559
577
|
return () => {
|
|
560
578
|
clearTimeout(settleTimer);
|
|
579
|
+
settleTimers.forEach(clearTimeout);
|
|
561
580
|
document.removeEventListener("pointerdown", onDown, true);
|
|
562
581
|
document.removeEventListener("pointerup", onUp, true);
|
|
563
582
|
document.removeEventListener("selectionchange", onSelectionChange);
|