MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / writeClipboardText

Function writeClipboardText

src/pages/options/routes/script/ScriptEditor.tsx:378–399  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

376 return selections.map((selection) => model.getValueInRange(selection)).join(model.getEOL());
377 };
378 const writeClipboardText = async (text: string) => {
379 if (navigator.clipboard?.writeText) {
380 try {
381 await navigator.clipboard.writeText(text);
382 return;
383 } catch {
384 // 失败时回落到下方的 execCommand 分支
385 }
386 }
387
388 const textarea = document.createElement("textarea");
389 textarea.value = text;
390 textarea.style.position = "fixed";
391 textarea.style.left = "-9999px";
392 textarea.style.top = "-9999px";
393 document.body.appendChild(textarea);
394 textarea.focus();
395 textarea.select();
396 const ok = document.execCommand("copy");
397 textarea.remove();
398 if (!ok) throw new Error("copy failed");
399 };
400 const copyEditorSelection = (editor: editor.ICodeEditor) => {
401 const text = getSelectedText(editor);
402 if (!text) return;

Callers 2

copyEditorSelectionFunction · 0.85
cutEditorSelectionFunction · 0.85

Calls 1

removeMethod · 0.65

Tested by

no test coverage detected