MCPcopy Create free account
hub / github.com/continuedev/continue / useCopy

Function useCopy

gui/src/hooks/useCopy.tsx:5–22  ·  view source on GitHub ↗
(text: string | (() => string))

Source from the content-addressed store, hash-verified

3import { isJetBrains } from "../util";
4
5export default function useCopy(text: string | (() => string)) {
6 const [copied, setCopied] = useState<boolean>(false);
7 const ideMessenger = useContext(IdeMessengerContext);
8
9 const copyText = useCallback(() => {
10 const textVal = typeof text === "string" ? text : text();
11 if (isJetBrains()) {
12 ideMessenger.post("copyText", { text: textVal });
13 } else {
14 navigator.clipboard.writeText(textVal);
15 }
16
17 setCopied(true);
18 setTimeout(() => setCopied(false), 2000);
19 }, [text, ideMessenger]);
20
21 return { copied, copyText };
22}

Callers 2

CopyButtonFunction · 0.85
CopyIconButtonFunction · 0.85

Calls 2

isJetBrainsFunction · 0.90
postMethod · 0.65

Tested by

no test coverage detected