diff --git a/webview-ui/src/components/history/HistoryView.tsx b/webview-ui/src/components/history/HistoryView.tsx index 1189cffc0e2..ea5c5cf6574 100644 --- a/webview-ui/src/components/history/HistoryView.tsx +++ b/webview-ui/src/components/history/HistoryView.tsx @@ -227,7 +227,12 @@ const HistoryView = ({ onDone }: HistoryViewProps) => { title="Delete Task" onClick={(e) => { e.stopPropagation() - setDeleteTaskId(item.id) + if (e.shiftKey) { + // directly delete without prompting if shift is pressed + vscode.postMessage({ type: "deleteTaskWithId", text: item.id }) + } else { + setDeleteTaskId(item.id) + } }}> {item.size && prettyBytes(item.size)} diff --git a/webview-ui/src/components/history/__tests__/HistoryView.test.tsx b/webview-ui/src/components/history/__tests__/HistoryView.test.tsx index 12b0181af6b..51e197713d8 100644 --- a/webview-ui/src/components/history/__tests__/HistoryView.test.tsx +++ b/webview-ui/src/components/history/__tests__/HistoryView.test.tsx @@ -135,26 +135,54 @@ describe("HistoryView", () => { }) }) - it("handles task deletion", async () => { - const onDone = jest.fn() - render() + describe("task deletion", () => { + it("shows confirmation dialog on regular click", () => { + const onDone = jest.fn() + render() + + // Find and hover over first task + const taskContainer = screen.getByTestId("virtuoso-item-1") + fireEvent.mouseEnter(taskContainer) + + // Click delete button to open confirmation dialog + const deleteButton = within(taskContainer).getByTitle("Delete Task") + fireEvent.click(deleteButton) + + // Verify dialog is shown + const dialog = screen.getByRole("alertdialog") + expect(dialog).toBeInTheDocument() + + // Find and click the confirm delete button in the dialog + const confirmDeleteButton = within(dialog).getByRole("button", { name: /delete/i }) + fireEvent.click(confirmDeleteButton) + + // Verify vscode message was sent + expect(vscode.postMessage).toHaveBeenCalledWith({ + type: "deleteTaskWithId", + text: "1", + }) + }) - // Find and hover over first task - const taskContainer = screen.getByTestId("virtuoso-item-1") - fireEvent.mouseEnter(taskContainer) + it("deletes immediately on shift-click without confirmation", () => { + const onDone = jest.fn() + render() - // Click delete button to open confirmation dialog - const deleteButton = within(taskContainer).getByTitle("Delete Task") - fireEvent.click(deleteButton) + // Find and hover over first task + const taskContainer = screen.getByTestId("virtuoso-item-1") + fireEvent.mouseEnter(taskContainer) - // Find and click the confirm delete button in the dialog - const confirmDeleteButton = screen.getByRole("button", { name: /delete/i }) - fireEvent.click(confirmDeleteButton) + // Shift-click delete button + const deleteButton = within(taskContainer).getByTitle("Delete Task") + fireEvent.click(deleteButton, { shiftKey: true }) - // Verify vscode message was sent - expect(vscode.postMessage).toHaveBeenCalledWith({ - type: "deleteTaskWithId", - text: "1", + // Verify no dialog is shown + expect(screen.queryByRole("alertdialog")).not.toBeInTheDocument() + + // Verify vscode message was sent + expect(vscode.postMessage).toHaveBeenCalledWith({ + type: "deleteTaskWithId", + text: "1", + }) }) })