From 5403db241f3743ffea770d5cbb4788408b0a3d57 Mon Sep 17 00:00:00 2001 From: Hannes Rudolph Date: Fri, 16 May 2025 17:29:01 -0600 Subject: [PATCH] fix copy button to preserve XML --- .../src/components/history/CopyButton.tsx | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/webview-ui/src/components/history/CopyButton.tsx b/webview-ui/src/components/history/CopyButton.tsx index 2ac8d2157e..9262562a20 100644 --- a/webview-ui/src/components/history/CopyButton.tsx +++ b/webview-ui/src/components/history/CopyButton.tsx @@ -13,16 +13,17 @@ export const CopyButton = ({ itemTask }: CopyButtonProps) => { const { isCopied, copy } = useClipboard() const { t } = useAppTranslation() - const onCopy = useCallback( - (e: React.MouseEvent) => { - e.stopPropagation() - const tempDiv = document.createElement("div") - tempDiv.innerHTML = itemTask - const text = tempDiv.textContent || tempDiv.innerText || "" - !isCopied && copy(text) - }, - [isCopied, copy, itemTask], - ) + const onCopy = useCallback( + (e: React.MouseEvent) => { + e.stopPropagation() + const withoutHighlights = itemTask.replace( + /(.*?)<\/span>/g, + "$1", + ) + !isCopied && copy(withoutHighlights) + }, + [isCopied, copy, itemTask], + ) return (