feat: add clipboard copy functionality to openImage for file paths

This commit is contained in:
daniel-lxs 2025-09-23 14:57:26 -05:00
parent addd1bc6e7
commit b10c87422a
No known key found for this signature in database
GPG key ID: 21C74479048B3AA6

View file

@ -16,10 +16,14 @@ export async function openImage(dataUriOrPath: string, options?: { values?: { ac
if (fsPath.startsWith("/file/")) {
fsPath = fsPath.slice("/file/".length)
}
fsPath = path.normalize(fsPath)
if (fsPath) {
const fileUri = vscode.Uri.file(fsPath)
if (options?.values?.action === "copy") {
await vscode.env.clipboard.writeText(fsPath)
vscode.window.showInformationMessage(t("common:info.path_copied_to_clipboard"))
return
}
await vscode.commands.executeCommand("vscode.open", fileUri)
return
}
@ -32,6 +36,13 @@ export async function openImage(dataUriOrPath: string, options?: { values?: { ac
if (dataUriOrPath.startsWith("file://")) {
try {
const fileUri = vscode.Uri.parse(dataUriOrPath)
const filePath = fileUri.fsPath
if (options?.values?.action === "copy") {
await vscode.env.clipboard.writeText(filePath)
vscode.window.showInformationMessage(t("common:info.path_copied_to_clipboard"))
return
}
await vscode.commands.executeCommand("vscode.open", fileUri)
} catch (error) {