Allow copy paste images and screenshots

This commit is contained in:
andrepimenta
2025-07-07 23:23:27 +01:00
parent bb20bb29c5
commit 0bdb0ce30a
2 changed files with 108 additions and 0 deletions

View File

@@ -234,6 +234,9 @@ class ClaudeChatProvider {
case 'openFile':
this._openFileInEditor(message.filePath);
return;
case 'createImageFile':
this._createImageFile(message.imageData, message.imageType);
return;
}
},
null,
@@ -1406,6 +1409,44 @@ class ClaudeChatProvider {
}
}
private async _createImageFile(imageData: string, imageType: string) {
try {
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
if (!workspaceFolder) {return;}
// Extract base64 data from data URL
const base64Data = imageData.split(',')[1];
const buffer = Buffer.from(base64Data, 'base64');
// Get file extension from image type
const extension = imageType.split('/')[1] || 'png';
// Create unique filename with timestamp
const timestamp = Date.now();
const imageFileName = `image_${timestamp}.${extension}`;
// Create images folder in workspace .vscode directory
const imagesDir = vscode.Uri.joinPath(workspaceFolder.uri, '.vscode', 'claude-code-chat-images');
await vscode.workspace.fs.createDirectory(imagesDir);
// Create the image file
const imagePath = vscode.Uri.joinPath(imagesDir, imageFileName);
await vscode.workspace.fs.writeFile(imagePath, buffer);
// Send the file path back to webview
this._panel?.webview.postMessage({
type: 'imagePath',
data: {
filePath: imagePath.fsPath
}
});
} catch (error) {
console.error('Error creating image file:', error);
vscode.window.showErrorMessage('Failed to create image file');
}
}
public dispose() {
if (this._panel) {
this._panel.dispose();