Skip to content

Commit

Permalink
Decreased polling delay to 1ms
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-danylchenko committed Oct 16, 2024
1 parent d8c57d1 commit 5d3a8a0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/text-annotator/src/SelectionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const SelectionHandler = (

const onSelectStart = (evt: Event) => {
isContextMenuOpen = false;

if (isLeftClick === false)
return;

Expand Down Expand Up @@ -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);

Expand All @@ -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));
Expand Down Expand Up @@ -301,15 +301,15 @@ 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.
}, 100);

// Listen to the change event that follows
document.addEventListener('selectionchange', onSelected);

// Start selection!
onSelectStart(evt);
}
Expand Down

0 comments on commit 5d3a8a0

Please sign in to comment.