MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / copyWithSelection

Function copyWithSelection

packages/studio/src/utils/clipboard.ts:1–31  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

1function copyWithSelection(text: string): boolean {
2 if (typeof document === "undefined" || !document.body || !document.execCommand) {
3 return false;
4 }
5
6 const textarea = document.createElement("textarea");
7 textarea.value = text;
8 textarea.setAttribute("readonly", "true");
9 textarea.style.position = "fixed";
10 textarea.style.top = "0";
11 textarea.style.left = "0";
12 textarea.style.width = "1px";
13 textarea.style.height = "1px";
14 textarea.style.padding = "0";
15 textarea.style.border = "0";
16 textarea.style.opacity = "0";
17 textarea.style.pointerEvents = "none";
18
19 document.body.appendChild(textarea);
20 textarea.focus({ preventScroll: true });
21 textarea.select();
22 textarea.setSelectionRange(0, text.length);
23
24 try {
25 return document.execCommand("copy");
26 } catch {
27 return false;
28 } finally {
29 document.body.removeChild(textarea);
30 }
31}
32
33function shouldCopyWithSelectionFirst(): boolean {
34 if (typeof navigator === "undefined") return false;

Callers 1

copyTextToClipboardFunction · 0.85

Calls 2

setAttributeMethod · 0.65
selectMethod · 0.65

Tested by

no test coverage detected