From 5d3a8a07864cc3b1d5056c7f0a12dc5ce4cc7ad1 Mon Sep 17 00:00:00 2001 From: Oleksandr Danylchenko Date: Wed, 16 Oct 2024 23:25:51 +0300 Subject: [PATCH] Decreased polling delay to 1ms --- packages/text-annotator/src/SelectionHandler.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/text-annotator/src/SelectionHandler.ts b/packages/text-annotator/src/SelectionHandler.ts index 836c4ab0..3fe2f813 100644 --- a/packages/text-annotator/src/SelectionHandler.ts +++ b/packages/text-annotator/src/SelectionHandler.ts @@ -55,7 +55,7 @@ export const SelectionHandler = ( const onSelectStart = (evt: Event) => { isContextMenuOpen = false; - + if (isLeftClick === false) return; @@ -250,7 +250,7 @@ export const SelectionHandler = ( let isCollapsed = sel?.isCollapsed; const shouldStopPolling = () => isCollapsed || stopPolling; - const pollingDelayMs = 2; + const pollingDelayMs = 1; const stopPollingInMs = 50; setTimeout(() => stopPolling = true, stopPollingInMs); @@ -264,12 +264,12 @@ export const SelectionHandler = ( if (sel?.isCollapsed) return; - // When selecting the initial word, Chrome Android fires `contextmenu` + // When selecting the initial word, Chrome Android fires `contextmenu` // before selectionChanged. if (!currentTarget || currentTarget.selector.length === 0) { onSelectionChange(evt); } - + upsertCurrentTarget(); selection.userSelect(currentTarget.annotation, clonePointerEvent(evt)); @@ -301,7 +301,7 @@ export const SelectionHandler = ( selection.userSelect(currentTarget.annotation, cloneKeyboardEvent(evt)); } - + document.removeEventListener('selectionchange', onSelected); // Sigh... this needs a delay to work. But doesn't seem reliable. @@ -309,7 +309,7 @@ export const SelectionHandler = ( // Listen to the change event that follows document.addEventListener('selectionchange', onSelected); - + // Start selection! onSelectStart(evt); }