Skip to content

Commit 433fe9b

Browse files
committed
fix copy button to strip highlights
1 parent 6e958df commit 433fe9b

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ 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 text = itemTask.replace(/<span class="history-item-highlight">|<\/span>/g, "")
20+
!isCopied && copy(text)
21+
},
22+
[isCopied, copy, itemTask],
23+
)
2624

2725
return (
2826
<Button

webview-ui/src/components/history/__tests__/HistoryView.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ describe("HistoryView", () => {
107107
const taskContainer = screen.getByTestId("virtuoso-item-1")
108108
fireEvent.mouseEnter(taskContainer)
109109
const copyButton = within(taskContainer).getByTestId("copy-prompt-button")
110-
fireEvent.click(copyButton)
111-
const taskContent = within(taskContainer).getByTestId("task-content")
112-
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(taskContent.textContent)
113-
})
110+
fireEvent.click(copyButton)
111+
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(mockTaskHistory[0].task)
112+
})
114113

115114
it("handles sort options correctly", async () => {
116115
const onDone = jest.fn()

0 commit comments

Comments
 (0)