From 30cf0d53198031e74755fef9964dcc98e36ec457 Mon Sep 17 00:00:00 2001
From: Hannes Rudolph <49103247+hannesrudolph@users.noreply.github.com>
Date: Fri, 7 Feb 2025 15:50:28 -0700
Subject: [PATCH 1/4] Update HistoryPreview.tsx
Added a copy button to the history preview view
---
.../src/components/history/HistoryPreview.tsx | 47 +++++++++++++++++--
1 file changed, 44 insertions(+), 3 deletions(-)
diff --git a/webview-ui/src/components/history/HistoryPreview.tsx b/webview-ui/src/components/history/HistoryPreview.tsx
index 08aca2a44d..562c110097 100644
--- a/webview-ui/src/components/history/HistoryPreview.tsx
+++ b/webview-ui/src/components/history/HistoryPreview.tsx
@@ -1,7 +1,7 @@
import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"
import { useExtensionState } from "../../context/ExtensionStateContext"
import { vscode } from "../../utils/vscode"
-import { memo } from "react"
+import { memo, useState } from "react"
import { formatLargeNumber } from "../../utils/format"
type HistoryPreviewProps = {
@@ -10,6 +10,18 @@ type HistoryPreviewProps = {
const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
const { taskHistory } = useExtensionState()
+ const [showCopyModal, setShowCopyModal] = useState(false)
+
+ const handleCopyTask = async (e: React.MouseEvent, task: string) => {
+ e.stopPropagation()
+ try {
+ await navigator.clipboard.writeText(task)
+ setShowCopyModal(true)
+ setTimeout(() => setShowCopyModal(false), 2000)
+ } catch (error) {
+ console.error("Failed to copy to clipboard:", error)
+ }
+ }
const handleHistorySelect = (id: string) => {
vscode.postMessage({ type: "showTaskWithId", text: id })
}
@@ -31,8 +43,30 @@ const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
return (
+ {showCopyModal &&
Prompt Copied to Clipboard
}
- {showCopyModal &&
Prompt Copied to Clipboard
}
+ {showCopyFeedback &&
Prompt Copied to Clipboard
}
{
title="Copy Prompt"
className="copy-button"
data-appearance="icon"
- onClick={(e) => handleCopyTask(e, item.task)}>
+ onClick={(e) => copyWithFeedback(item.task, e)}>