Skip to content

Commit f39225e

Browse files
committed
fix: an issue in the HistoryView component where keywords in copied content contain html code
1 parent 677e145 commit f39225e

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

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

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

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
9292
}}
9393
data={tasks}
9494
data-testid="virtuoso-container"
95+
initialTopMostItemIndex={0}
9596
components={{
9697
List: React.forwardRef((props, ref) => (
9798
<div {...props} ref={ref} data-testid="virtuoso-item-list" />
@@ -159,6 +160,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
159160
wordBreak: "break-word",
160161
overflowWrap: "anywhere",
161162
}}
163+
data-testid="task-content"
162164
dangerouslySetInnerHTML={{ __html: item.task }}
163165
/>
164166
<div style={{ display: "flex", flexDirection: "column", gap: "4px" }}>
@@ -304,8 +306,8 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
304306
</span>
305307
</div>
306308
<div className="flex flex-row gap-1">
307-
<CopyButton itemTask={item.task} />
308-
<ExportButton itemId={item.id} />
309+
<CopyButton itemTask={item.task} />
310+
<ExportButton itemId={item.id} />
309311
</div>
310312
</div>
311313
)}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { vscode } from "../../../utils/vscode"
77

88
jest.mock("../../../context/ExtensionStateContext")
99
jest.mock("../../../utils/vscode")
10-
10+
1111
jest.mock("react-virtuoso", () => ({
1212
Virtuoso: ({ data, itemContent }: any) => (
1313
<div data-testid="virtuoso-container">
@@ -70,6 +70,12 @@ describe("HistoryView", () => {
7070
})
7171

7272
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+
7379
const onDone = jest.fn()
7480
render(<HistoryView onDone={onDone} />)
7581

@@ -96,6 +102,14 @@ describe("HistoryView", () => {
96102
// Verify radio button is checked
97103
const updatedRadio = within(radioGroup).getByRole("radio", { name: "Most Relevant", checked: true })
98104
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).getByTitle("Copy Prompt");
110+
fireEvent.click(copyButton);
111+
const taskContent = within(taskContainer).getByTestId("task-content");
112+
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(taskContent.textContent);
99113
})
100114

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

0 commit comments

Comments
 (0)