MCPcopy Create free account
hub / github.com/anomalyco/opencode / writeClipboard

Function writeClipboard

packages/session-ui/src/components/message-part.tsx:66–88  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

64import { readPartText } from "./message-part-text"
65
66async function writeClipboard(text: string): Promise<boolean> {
67 const body = typeof document === "undefined" ? undefined : document.body
68 if (body) {
69 const textarea = document.createElement("textarea")
70 textarea.value = text
71 textarea.setAttribute("readonly", "")
72 textarea.style.position = "fixed"
73 textarea.style.opacity = "0"
74 textarea.style.pointerEvents = "none"
75 body.appendChild(textarea)
76 textarea.select()
77 const copied = document.execCommand("copy")
78 body.removeChild(textarea)
79 if (copied) return true
80 }
81
82 const clipboard = typeof navigator === "undefined" ? undefined : navigator.clipboard
83 if (!clipboard?.writeText) return false
84 return clipboard.writeText(text).then(
85 () => true,
86 () => false,
87 )
88}
89
90function ShellSubmessage(props: { text: string; animate?: boolean }) {
91 let widthRef: HTMLSpanElement | undefined

Callers 1

handleCopyFunction · 0.85

Calls 1

selectMethod · 0.45

Tested by

no test coverage detected