Skip to content

Commit 30cf0d5

Browse files
Update HistoryPreview.tsx
Added a copy button to the history preview view
1 parent 14d7691 commit 30cf0d5

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

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

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"
22
import { useExtensionState } from "../../context/ExtensionStateContext"
33
import { vscode } from "../../utils/vscode"
4-
import { memo } from "react"
4+
import { memo, useState } from "react"
55
import { formatLargeNumber } from "../../utils/format"
66

77
type HistoryPreviewProps = {
@@ -10,6 +10,18 @@ type HistoryPreviewProps = {
1010

1111
const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
1212
const { taskHistory } = useExtensionState()
13+
const [showCopyModal, setShowCopyModal] = useState(false)
14+
15+
const handleCopyTask = async (e: React.MouseEvent, task: string) => {
16+
e.stopPropagation()
17+
try {
18+
await navigator.clipboard.writeText(task)
19+
setShowCopyModal(true)
20+
setTimeout(() => setShowCopyModal(false), 2000)
21+
} catch (error) {
22+
console.error("Failed to copy to clipboard:", error)
23+
}
24+
}
1325
const handleHistorySelect = (id: string) => {
1426
vscode.postMessage({ type: "showTaskWithId", text: id })
1527
}
@@ -31,8 +43,30 @@ const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
3143

3244
return (
3345
<div style={{ flexShrink: 0 }}>
46+
{showCopyModal && <div className="copy-modal">Prompt Copied to Clipboard</div>}
3447
<style>
3548
{`
49+
.copy-modal {
50+
position: fixed;
51+
top: 50%;
52+
left: 50%;
53+
transform: translate(-50%, -50%);
54+
background-color: var(--vscode-notifications-background);
55+
color: var(--vscode-notifications-foreground);
56+
padding: 12px 20px;
57+
border-radius: 4px;
58+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
59+
z-index: 1000;
60+
transition: opacity 0.2s ease-in-out;
61+
}
62+
.copy-button {
63+
opacity: 0;
64+
pointer-events: none;
65+
}
66+
.history-preview-item:hover .copy-button {
67+
opacity: 1;
68+
pointer-events: auto;
69+
}
3670
.history-preview-item {
3771
background-color: color-mix(in srgb, var(--vscode-toolbar-hoverBackground) 65%, transparent);
3872
border-radius: 4px;
@@ -79,8 +113,8 @@ const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
79113
key={item.id}
80114
className="history-preview-item"
81115
onClick={() => handleHistorySelect(item.id)}>
82-
<div style={{ padding: "12px" }}>
83-
<div style={{ marginBottom: "8px" }}>
116+
<div style={{ padding: "12px", position: "relative" }}>
117+
<div style={{ marginBottom: "8px", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
84118
<span
85119
style={{
86120
color: "var(--vscode-descriptionForeground)",
@@ -90,6 +124,13 @@ const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
90124
}}>
91125
{formatDate(item.ts)}
92126
</span>
127+
<button
128+
title="Copy Prompt"
129+
className="copy-button"
130+
data-appearance="icon"
131+
onClick={(e) => handleCopyTask(e, item.task)}>
132+
<span className="codicon codicon-copy"></span>
133+
</button>
93134
</div>
94135
<div
95136
style={{

0 commit comments

Comments
 (0)