Skip to content

Commit 2fda825

Browse files
committed
feat(preview): add copy-to-clipboard functionality
- Added copy buttons to public ID in Info tab - Added copy buttons to URLs (original and optimized) in URLs tab - Included visual feedback with 'Copied!' confirmation (2s duration) - Styled buttons to match VS Code theme variables - Uses native navigator.clipboard API
1 parent d8d4490 commit 2fda825

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/commands/previewAsset.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ function registerPreview(context: vscode.ExtensionContext) {
111111
a:hover {
112112
text-decoration: underline;
113113
}
114+
115+
.copy-btn {
116+
background-color: var(--vscode-button-background);
117+
color: var(--vscode-button-foreground);
118+
border: none;
119+
padding: 0.25rem 0.5rem;
120+
border-radius: 4px;
121+
cursor: pointer;
122+
font-size: 0.85rem;
123+
margin-left: 0.5rem;
124+
}
125+
126+
.copy-btn:hover {
127+
background-color: var(--vscode-button-hoverBackground);
128+
}
129+
130+
.copy-btn:active {
131+
background-color: var(--vscode-button-activeBackground);
132+
}
114133
</style>
115134
</head>
116135
<body>
@@ -125,7 +144,7 @@ function registerPreview(context: vscode.ExtensionContext) {
125144
</nav>
126145
127146
<div class="tab-content active" id="tab-info">
128-
<p><strong>Public ID:</strong> ${asset.public_id}</p>
147+
<p><strong>Public ID:</strong> ${asset.public_id} <button class="copy-btn" data-copy="${asset.public_id}">Copy</button></p>
129148
<p><strong>Original filename:</strong> ${asset.filename}</p>
130149
<p><strong>Dimensions:</strong> ${asset.width} x ${asset.height}</p>
131150
<p><strong>Size:</strong> ${(asset.bytes / 1024).toFixed(2)} KB</p>
@@ -156,8 +175,8 @@ function registerPreview(context: vscode.ExtensionContext) {
156175
</div>
157176
158177
<div class="tab-content" id="tab-urls">
159-
<p><strong>Original URL:</strong> <a href="${asset.secure_url}" target="_blank">${asset.secure_url}</a></p>
160-
<p><strong>Optimized URL:</strong> <a href="${asset.optimized_url}" target="_blank">${asset.optimized_url}</a></p>
178+
<p><strong>Original URL:</strong> <a href="${asset.secure_url}" target="_blank">${asset.secure_url}</a> <button class="copy-btn" data-copy="${asset.secure_url}">Copy</button></p>
179+
<p><strong>Optimized URL:</strong> <a href="${asset.optimized_url}" target="_blank">${asset.optimized_url}</a> <button class="copy-btn" data-copy="${asset.optimized_url}">Copy</button></p>
161180
</div>
162181
</div>
163182
@@ -175,6 +194,21 @@ function registerPreview(context: vscode.ExtensionContext) {
175194
if (target) target.classList.add("active");
176195
});
177196
});
197+
198+
// Copy button functionality
199+
const copyButtons = document.querySelectorAll(".copy-btn");
200+
copyButtons.forEach((btn) => {
201+
btn.addEventListener("click", () => {
202+
const textToCopy = btn.getAttribute("data-copy");
203+
navigator.clipboard.writeText(textToCopy).then(() => {
204+
const originalText = btn.textContent;
205+
btn.textContent = "Copied!";
206+
setTimeout(() => {
207+
btn.textContent = originalText;
208+
}, 2000);
209+
});
210+
});
211+
});
178212
</script>
179213
</body>
180214
</html>

0 commit comments

Comments
 (0)