Skip to content

Commit a17be07

Browse files
im47cnmrubens
andauthored
fix: an issue in the HistoryView component where keywords in copied content contain html code (#1662)
* fix: an issue in the HistoryView component where keywords in copied content contain html code * Update webview-ui/src/components/history/HistoryView.tsx * Fix test --------- Co-authored-by: Matt Rubens <[email protected]>
1 parent 56ff9ea commit a17be07

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export const CopyButton = ({ itemTask }: CopyButtonProps) => {
1616
const onCopy = useCallback(
1717
(e: React.MouseEvent) => {
1818
e.stopPropagation()
19-
!isCopied && copy(itemTask)
19+
const tempDiv = document.createElement('div');
20+
tempDiv.innerHTML = itemTask;
21+
const text = tempDiv.textContent || tempDiv.innerText || "";
22+
!isCopied && copy(text)
2023
},
2124
[isCopied, copy, itemTask],
2225
)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
104104
}}
105105
data={tasks}
106106
data-testid="virtuoso-container"
107+
initialTopMostItemIndex={0}
107108
components={{
108109
List: React.forwardRef((props, ref) => (
109110
<div {...props} ref={ref} data-testid="virtuoso-item-list" />
@@ -172,6 +173,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
172173
wordBreak: "break-word",
173174
overflowWrap: "anywhere",
174175
}}
176+
data-testid="task-content"
175177
dangerouslySetInnerHTML={{ __html: item.task }}
176178
/>
177179
<div style={{ display: "flex", flexDirection: "column", gap: "4px" }}>

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { vscode } from "../../../utils/vscode"
88
jest.mock("../../../context/ExtensionStateContext")
99
jest.mock("../../../utils/vscode")
1010
jest.mock("../../../i18n/TranslationContext")
11-
1211
jest.mock("react-virtuoso", () => ({
1312
Virtuoso: ({ data, itemContent }: any) => (
1413
<div data-testid="virtuoso-container">
@@ -71,6 +70,12 @@ describe("HistoryView", () => {
7170
})
7271

7372
it("handles search functionality", () => {
73+
// Setup clipboard mock that resolves immediately
74+
const mockClipboard = {
75+
writeText: jest.fn().mockResolvedValue(undefined),
76+
}
77+
Object.assign(navigator, { clipboard: mockClipboard })
78+
7479
const onDone = jest.fn()
7580
render(<HistoryView onDone={onDone} />)
7681

@@ -97,6 +102,14 @@ describe("HistoryView", () => {
97102
// Verify radio button is checked
98103
const updatedRadio = within(radioGroup).getByTestId("radio-most-relevant")
99104
expect(updatedRadio).toBeInTheDocument()
105+
106+
// Verify copy the plain text content of the task when the copy button is clicked
107+
const taskContainer = screen.getByTestId("virtuoso-item-1")
108+
fireEvent.mouseEnter(taskContainer)
109+
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)
100113
})
101114

102115
it("handles sort options correctly", async () => {

0 commit comments

Comments
 (0)