From f39225e11756efad3d88b1bbb0f7e099e545dc9b Mon Sep 17 00:00:00 2001
From: im47cn <67424112+im47cn@users.noreply.github.com>
Date: Sat, 15 Mar 2025 12:52:30 +0800
Subject: [PATCH 1/3] fix: an issue in the HistoryView component where keywords
in copied content contain html code
---
webview-ui/src/components/history/CopyButton.tsx | 5 ++++-
.../src/components/history/HistoryView.tsx | 6 ++++--
.../history/__tests__/HistoryView.test.tsx | 16 +++++++++++++++-
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/webview-ui/src/components/history/CopyButton.tsx b/webview-ui/src/components/history/CopyButton.tsx
index 0e693b44703..e7d01ffdcfd 100644
--- a/webview-ui/src/components/history/CopyButton.tsx
+++ b/webview-ui/src/components/history/CopyButton.tsx
@@ -14,7 +14,10 @@ export const CopyButton = ({ itemTask }: CopyButtonProps) => {
const onCopy = useCallback(
(e: React.MouseEvent) => {
e.stopPropagation()
- !isCopied && copy(itemTask)
+ const tempDiv = document.createElement('div');
+ tempDiv.innerHTML = itemTask;
+ const text = tempDiv.textContent || tempDiv.innerText || "";
+ !isCopied && copy(text)
},
[isCopied, copy, itemTask],
)
diff --git a/webview-ui/src/components/history/HistoryView.tsx b/webview-ui/src/components/history/HistoryView.tsx
index ec44f8eaca9..7b8d5959bae 100644
--- a/webview-ui/src/components/history/HistoryView.tsx
+++ b/webview-ui/src/components/history/HistoryView.tsx
@@ -92,6 +92,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
}}
data={tasks}
data-testid="virtuoso-container"
+ initialTopMostItemIndex={0}
components={{
List: React.forwardRef((props, ref) => (
@@ -159,6 +160,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
wordBreak: "break-word",
overflowWrap: "anywhere",
}}
+ data-testid="task-content"
dangerouslySetInnerHTML={{ __html: item.task }}
/>
@@ -304,8 +306,8 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
-
-
+
+
)}
diff --git a/webview-ui/src/components/history/__tests__/HistoryView.test.tsx b/webview-ui/src/components/history/__tests__/HistoryView.test.tsx
index 3eb9f9705b4..1bd7dd4f0ea 100644
--- a/webview-ui/src/components/history/__tests__/HistoryView.test.tsx
+++ b/webview-ui/src/components/history/__tests__/HistoryView.test.tsx
@@ -7,7 +7,7 @@ import { vscode } from "../../../utils/vscode"
jest.mock("../../../context/ExtensionStateContext")
jest.mock("../../../utils/vscode")
-
+
jest.mock("react-virtuoso", () => ({
Virtuoso: ({ data, itemContent }: any) => (
@@ -70,6 +70,12 @@ describe("HistoryView", () => {
})
it("handles search functionality", () => {
+ // Setup clipboard mock that resolves immediately
+ const mockClipboard = {
+ writeText: jest.fn().mockResolvedValue(undefined),
+ }
+ Object.assign(navigator, { clipboard: mockClipboard })
+
const onDone = jest.fn()
render()
@@ -96,6 +102,14 @@ describe("HistoryView", () => {
// Verify radio button is checked
const updatedRadio = within(radioGroup).getByRole("radio", { name: "Most Relevant", checked: true })
expect(updatedRadio).toBeInTheDocument()
+
+ // Verify copy the plain text content of the task when the copy button is clicked
+ const taskContainer = screen.getByTestId("virtuoso-item-1")
+ fireEvent.mouseEnter(taskContainer)
+ const copyButton = within(taskContainer).getByTitle("Copy Prompt");
+ fireEvent.click(copyButton);
+ const taskContent = within(taskContainer).getByTestId("task-content");
+ expect(navigator.clipboard.writeText).toHaveBeenCalledWith(taskContent.textContent);
})
it("handles sort options correctly", async () => {
From aa1024d6a92d987b9bb4d3a33cfb37734d07b8e0 Mon Sep 17 00:00:00 2001
From: Matt Rubens
Date: Mon, 17 Mar 2025 16:55:20 -0400
Subject: [PATCH 2/3] Update webview-ui/src/components/history/HistoryView.tsx
---
webview-ui/src/components/history/HistoryView.tsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/webview-ui/src/components/history/HistoryView.tsx b/webview-ui/src/components/history/HistoryView.tsx
index c3ade9f87ff..7caa968a990 100644
--- a/webview-ui/src/components/history/HistoryView.tsx
+++ b/webview-ui/src/components/history/HistoryView.tsx
@@ -308,8 +308,8 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
-
-
+
+
)}
From d2ec53a03b286af4a768c92412a1426319c732bb Mon Sep 17 00:00:00 2001
From: Matt Rubens
Date: Mon, 17 Mar 2025 17:02:58 -0400
Subject: [PATCH 3/3] Fix test
---
.../src/components/history/__tests__/HistoryView.test.tsx | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/webview-ui/src/components/history/__tests__/HistoryView.test.tsx b/webview-ui/src/components/history/__tests__/HistoryView.test.tsx
index b9096ff6d2a..379f7ccda75 100644
--- a/webview-ui/src/components/history/__tests__/HistoryView.test.tsx
+++ b/webview-ui/src/components/history/__tests__/HistoryView.test.tsx
@@ -106,10 +106,10 @@ describe("HistoryView", () => {
// Verify copy the plain text content of the task when the copy button is clicked
const taskContainer = screen.getByTestId("virtuoso-item-1")
fireEvent.mouseEnter(taskContainer)
- const copyButton = within(taskContainer).getByTitle("Copy Prompt");
- fireEvent.click(copyButton);
- const taskContent = within(taskContainer).getByTestId("task-content");
- expect(navigator.clipboard.writeText).toHaveBeenCalledWith(taskContent.textContent);
+ const copyButton = within(taskContainer).getByTestId("copy-prompt-button")
+ fireEvent.click(copyButton)
+ const taskContent = within(taskContainer).getByTestId("task-content")
+ expect(navigator.clipboard.writeText).toHaveBeenCalledWith(taskContent.textContent)
})
it("handles sort options correctly", async () => {