MCPcopy
hub / github.com/zai-org/GLM-OCR / fallbackCopy

Function fallbackCopy

apps/frontend/src/libs/utils.ts:25–54  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

23
24// 经典降级方案:创建隐藏 textarea + execCommand
25function fallbackCopy(text: string): Promise<boolean> {
26 return new Promise((resolve) => {
27 const textArea = document.createElement('textarea');
28
29 // 防止滚动跳动 + 移动端键盘弹出
30 textArea.value = text;
31 textArea.style.position = 'fixed';
32 textArea.style.top = '0';
33 textArea.style.left = '0';
34 textArea.style.opacity = '0';
35 textArea.style.pointerEvents = 'none'; // 防止干扰点击
36
37 // 兼容 iOS 需要这个
38 textArea.setAttribute('readonly', 'true');
39
40 document.body.appendChild(textArea);
41 textArea.focus();
42 textArea.select();
43
44 try {
45 const successful = document.execCommand('copy');
46 resolve(successful);
47 } catch (err) {
48 console.error('复制失败:', err);
49 resolve(false);
50 } finally {
51 document.body.removeChild(textArea);
52 }
53 });
54}

Callers 1

copyToClipboardFunction · 0.85

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected