fix: enable text selection codeblock

This commit is contained in:
Faisal Amir 2024-01-08 23:13:42 +07:00
parent 6c9cc9bb86
commit 067eb4e4d1

View File

@ -85,11 +85,10 @@ const SimpleTextMessage: React.FC<ThreadMessage> = (props) => {
const codeBlockCopyEvent = useRef((e: Event) => { const codeBlockCopyEvent = useRef((e: Event) => {
const target: HTMLElement = e.target as HTMLElement const target: HTMLElement = e.target as HTMLElement
if (typeof target.className !== 'string') return null if (typeof target.className !== 'string') return null
const isCopyActionClassName = target?.className.includes('copy-action')
const isCodeBlockParent =
target.parentElement?.parentElement?.className.includes('code-block')
if (isCopyActionClassName || isCodeBlockParent) { const isCopyActionClassName = target?.className.includes('copy-action')
if (isCopyActionClassName) {
const content = target?.parentNode?.querySelector('code')?.innerText ?? '' const content = target?.parentNode?.querySelector('code')?.innerText ?? ''
clipboard.copy(content) clipboard.copy(content)
} }