Skip to content

Commit 89f260b

Browse files
authored
fix(CodeBlock.tsx): fix copy-to-clipboard functionality. The code has been updated to use the copy function from the copy-to-clipboard library instead of the (danny-avila#806)
avigator.clipboard.writeText method. This should fix the issue with browser incompatibility with navigator SDK and allow users to copy code from the CodeBlock component successfully.
1 parent d00c735 commit 89f260b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

client/src/components/Messages/Content/CodeBlock.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useRef, useState, RefObject } from 'react';
2+
import copy from 'copy-to-clipboard';
23
import { Clipboard, CheckMark } from '~/components';
34
import { InfoIcon } from 'lucide-react';
45
import { cn } from '~/utils/';
@@ -22,10 +23,12 @@ const CodeBar: React.FC<CodeBarProps> = React.memo(({ lang, codeRef, plugin = nu
2223
onClick={async () => {
2324
const codeString = codeRef.current?.textContent;
2425
if (codeString) {
25-
navigator.clipboard.writeText(codeString).then(() => {
26-
setIsCopied(true);
27-
setTimeout(() => setIsCopied(false), 3000);
28-
});
26+
setIsCopied(true);
27+
copy(codeString);
28+
29+
setTimeout(() => {
30+
setIsCopied(false);
31+
}, 3000);
2932
}
3033
}}
3134
>

0 commit comments

Comments
 (0)