From 117110041748f04fa22c1e7ea6415ac0cad35a2a Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Mon, 25 Nov 2024 13:56:41 +0800 Subject: [PATCH] fix: code block copy button missing --- src/renderer/src/pages/home/Markdown/CodeBlock.tsx | 4 +++- src/renderer/src/pages/home/Messages/Messages.tsx | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/pages/home/Markdown/CodeBlock.tsx b/src/renderer/src/pages/home/Markdown/CodeBlock.tsx index 6e817d6e..63ff6fb3 100644 --- a/src/renderer/src/pages/home/Markdown/CodeBlock.tsx +++ b/src/renderer/src/pages/home/Markdown/CodeBlock.tsx @@ -39,7 +39,6 @@ const ExpandButton: React.FC<{ const CodeBlock: React.FC = ({ children, className }) => { const match = /language-(\w+)/.exec(className || '') - const showFooterCopyButton = children && children.length > 500 const { codeShowLineNumbers, fontSize, codeCollapsible } = useSettings() const language = match?.[1] ?? 'text' const [html, setHtml] = useState('') @@ -48,6 +47,8 @@ const CodeBlock: React.FC = ({ children, className }) => { const [shouldShowExpandButton, setShouldShowExpandButton] = useState(false) const codeContentRef = useRef(null) + const showFooterCopyButton = children && children.length > 500 && !codeCollapsible + useEffect(() => { const loadHighlightedCode = async () => { const highlightedHtml = await codeToHtml(children, language) @@ -196,6 +197,7 @@ const CodeFooter = styled.div` flex-direction: row; justify-content: flex-end; align-items: center; + position: relative; .copy { cursor: pointer; color: var(--color-text-3); diff --git a/src/renderer/src/pages/home/Messages/Messages.tsx b/src/renderer/src/pages/home/Messages/Messages.tsx index ba05819e..fefdbe06 100644 --- a/src/renderer/src/pages/home/Messages/Messages.tsx +++ b/src/renderer/src/pages/home/Messages/Messages.tsx @@ -44,7 +44,7 @@ const Messages: FC = ({ assistant, topic, setActiveTopic }) => { const showRightTopics = showTopics && topicPosition === 'right' const minusAssistantsWidth = showAssistants ? '- var(--assistants-width)' : '' const minusRightTopicsWidth = showRightTopics ? '- var(--assistants-width)' : '' - return `calc(100vw - var(--sidebar-width) ${minusAssistantsWidth} ${minusRightTopicsWidth})` + return `calc(100vw - var(--sidebar-width) ${minusAssistantsWidth} ${minusRightTopicsWidth} - 5px)` }, [showAssistants, showTopics, topicPosition]) const scrollToBottom = useCallback(() => {