From a23a1916150e856281b3e195d79973453d114d84 Mon Sep 17 00:00:00 2001 From: crazywoola <100913391+crazywoola@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:34:51 +0800 Subject: [PATCH] feat: add copy button to code (#3719) --- web/app/components/app/chat/style.module.css | 6 +++++- web/app/components/base/markdown.tsx | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/web/app/components/app/chat/style.module.css b/web/app/components/app/chat/style.module.css index 0e0d67e35a..b0c8aba524 100644 --- a/web/app/components/app/chat/style.module.css +++ b/web/app/components/app/chat/style.module.css @@ -44,6 +44,10 @@ display: none; } +pre:hover .copyBtn { + display: block; +} + .answerWrapWrap, .questionWrapWrap { width: 0; @@ -129,4 +133,4 @@ .textArea:focus+div .sendBtn { background-image: url(./icons/send-active.svg); -} \ No newline at end of file +} diff --git a/web/app/components/base/markdown.tsx b/web/app/components/base/markdown.tsx index 77ddcabed9..be1a45476a 100644 --- a/web/app/components/base/markdown.tsx +++ b/web/app/components/base/markdown.tsx @@ -82,7 +82,6 @@ const useLazyLoad = (ref: RefObject): boolean => { } export function Markdown(props: { content: string; className?: string }) { - const [isCopied, setIsCopied] = useState(false) const [isSVG, setIsSVG] = useState(false) return (
@@ -92,7 +91,7 @@ export function Markdown(props: { content: string; className?: string }) { RehypeKatex, ]} components={{ - code({ node, inline, className, children, ...props }) { + code({ inline, className, children, ...props }) { const match = /language-(\w+)/.exec(className || '') const language = match?.[1] const languageShowName = getCorrectCapitalizationLanguageName(language || '')