MCPcopy Create free account
hub / github.com/dailydotdev/apps / withSelectionGuard

Function withSelectionGuard

packages/shared/src/lib/click.ts:31–44  ·  view source on GitHub ↗
(
  handler: React.MouseEventHandler<T>,
)

Source from the content-addressed store, hash-verified

29// navigating away on mouseup. This guard preempts that navigation when the
30// click is the tail end of a text selection gesture.
31export const withSelectionGuard = <T = HTMLAnchorElement>(
32 handler: React.MouseEventHandler<T>,
33): React.MouseEventHandler<T> => {
34 return (event) => {
35 const selection = globalThis?.window?.getSelection();
36 const hasSelection =
37 !!selection && selection.anchorOffset !== selection.focusOffset;
38 if (hasSelection) {
39 event.preventDefault();
40 return;
41 }
42 handler(event);
43 };
44};

Callers 2

CommonSharePostContentFunction · 0.90
ShareYouTubeContentFunction · 0.90

Calls 1

handlerFunction · 0.50

Tested by

no test coverage detected