Skip to content

Commit 5403db2

Browse files
committed
fix copy button to preserve XML
1 parent 6e958df commit 5403db2

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

webview-ui/src/components/history/CopyButton.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ export const CopyButton = ({ itemTask }: CopyButtonProps) => {
1313
const { isCopied, copy } = useClipboard()
1414
const { t } = useAppTranslation()
1515

16-
const onCopy = useCallback(
17-
(e: React.MouseEvent) => {
18-
e.stopPropagation()
19-
const tempDiv = document.createElement("div")
20-
tempDiv.innerHTML = itemTask
21-
const text = tempDiv.textContent || tempDiv.innerText || ""
22-
!isCopied && copy(text)
23-
},
24-
[isCopied, copy, itemTask],
25-
)
16+
const onCopy = useCallback(
17+
(e: React.MouseEvent) => {
18+
e.stopPropagation()
19+
const withoutHighlights = itemTask.replace(
20+
/<span class="history-item-highlight">(.*?)<\/span>/g,
21+
"$1",
22+
)
23+
!isCopied && copy(withoutHighlights)
24+
},
25+
[isCopied, copy, itemTask],
26+
)
2627

2728
return (
2829
<Button

0 commit comments

Comments
 (0)