MCPcopy Index your code
hub / github.com/ColmapView/Colmapview.github.io / copyToClipboard

Function copyToClipboard

src/utils/clipboard.ts:37–67  ·  view source on GitHub ↗
(
  text: string,
  deps: CopyToClipboardDeps = {}
)

Source from the content-addressed store, hash-verified

35export const SCREENSHOT_COPY_SUCCESS_DURATION = 4000;
36
37export async function copyToClipboard(
38 text: string,
39 deps: CopyToClipboardDeps = {}
40): Promise<boolean> {
41 const clipboard = deps.clipboard ?? navigator.clipboard;
42 if (clipboard) {
43 try {
44 await clipboard.writeText(text);
45 return true;
46 } catch {
47 // Fall through to the textarea copy path for older or restricted browsers.
48 }
49 }
50
51 const documentRef = deps.document ?? document;
52 const textarea = documentRef.createElement('textarea');
53 textarea.value = text;
54 textarea.style.position = 'fixed';
55 textarea.style.opacity = '0';
56 documentRef.body.appendChild(textarea);
57 textarea.select();
58
59 try {
60 const execCommand = deps.execCommand ?? documentRef.execCommand.bind(documentRef);
61 return execCommand('copy');
62 } catch {
63 return false;
64 } finally {
65 documentRef.body.removeChild(textarea);
66 }
67}
68
69export async function copyWithFeedback(
70 text: string,

Callers 2

clipboard.test.tsFile · 0.90
copyWithFeedbackFunction · 0.85

Calls 1

writeTextMethod · 0.80

Tested by

no test coverage detected