mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
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 (#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.
This commit is contained in:
parent
d00c7354cd
commit
89f260bc78
1 changed files with 7 additions and 4 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { useRef, useState, RefObject } from 'react';
|
import React, { useRef, useState, RefObject } from 'react';
|
||||||
|
import copy from 'copy-to-clipboard';
|
||||||
import { Clipboard, CheckMark } from '~/components';
|
import { Clipboard, CheckMark } from '~/components';
|
||||||
import { InfoIcon } from 'lucide-react';
|
import { InfoIcon } from 'lucide-react';
|
||||||
import { cn } from '~/utils/';
|
import { cn } from '~/utils/';
|
||||||
|
|
@ -22,10 +23,12 @@ const CodeBar: React.FC<CodeBarProps> = React.memo(({ lang, codeRef, plugin = nu
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const codeString = codeRef.current?.textContent;
|
const codeString = codeRef.current?.textContent;
|
||||||
if (codeString) {
|
if (codeString) {
|
||||||
navigator.clipboard.writeText(codeString).then(() => {
|
|
||||||
setIsCopied(true);
|
setIsCopied(true);
|
||||||
setTimeout(() => setIsCopied(false), 3000);
|
copy(codeString);
|
||||||
});
|
|
||||||
|
setTimeout(() => {
|
||||||
|
setIsCopied(false);
|
||||||
|
}, 3000);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue