feat:对本地文件进行修改
- 对某一行进行修改 - 将文件中的某些词进行替换 - 将文件重命名
This commit is contained in:
@ -145,6 +145,38 @@ export function getWebviewContent(iconUri?: string): string {
|
||||
border-radius: 4px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.file-editor-section {
|
||||
margin-bottom: 20px;
|
||||
padding: 15px;
|
||||
background: var(--vscode-input-background);
|
||||
border: 1px solid var(--vscode-input-border);
|
||||
border-radius: 8px;
|
||||
display: none;
|
||||
}
|
||||
.file-editor-section.active {
|
||||
display: block;
|
||||
}
|
||||
.file-editor-section h3 {
|
||||
margin: 0 0 10px 0;
|
||||
color: var(--vscode-button-background);
|
||||
}
|
||||
.file-editor-textarea {
|
||||
width: 100%;
|
||||
min-height: 300px;
|
||||
padding: 10px;
|
||||
background: var(--vscode-editor-background);
|
||||
color: var(--vscode-editor-foreground);
|
||||
border: 1px solid var(--vscode-input-border);
|
||||
border-radius: 4px;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 12px;
|
||||
resize: vertical;
|
||||
}
|
||||
.editor-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -172,6 +204,15 @@ export function getWebviewContent(iconUri?: string): string {
|
||||
<div id="errorMessage" style="display: none;"></div>
|
||||
</div>
|
||||
|
||||
<div id="fileEditorSection" class="file-editor-section">
|
||||
<h3>✏️ 编辑文件: <span id="editingFileName"></span></h3>
|
||||
<textarea id="fileEditorTextarea" class="file-editor-textarea"></textarea>
|
||||
<div class="editor-actions">
|
||||
<button onclick="saveFile()">保存修改</button>
|
||||
<button onclick="cancelEdit()" style="background: var(--vscode-button-secondaryBackground); color: var(--vscode-button-secondaryForeground);">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chat-container">
|
||||
<div id="messages" class="messages">
|
||||
<div class="message bot-message">
|
||||
@ -204,6 +245,11 @@ export function getWebviewContent(iconUri?: string): string {
|
||||
const filePathInput = document.getElementById('filePathInput');
|
||||
const fileContentEl = document.getElementById('fileContent');
|
||||
const errorMessageEl = document.getElementById('errorMessage');
|
||||
const fileEditorSection = document.getElementById('fileEditorSection');
|
||||
const fileEditorTextarea = document.getElementById('fileEditorTextarea');
|
||||
const editingFileName = document.getElementById('editingFileName');
|
||||
|
||||
let currentEditingFile = null;
|
||||
|
||||
function sendMessage() {
|
||||
const text = messageInput.value.trim();
|
||||
@ -268,6 +314,42 @@ export function getWebviewContent(iconUri?: string): string {
|
||||
messagesEl.scrollTop = messagesEl.scrollHeight;
|
||||
}
|
||||
|
||||
function openFileEditor(filePath, content) {
|
||||
currentEditingFile = filePath;
|
||||
editingFileName.textContent = filePath;
|
||||
fileEditorTextarea.value = content;
|
||||
fileEditorSection.classList.add('active');
|
||||
|
||||
// 滚动到编辑器位置
|
||||
fileEditorSection.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
|
||||
// 在消息区域显示提示
|
||||
addMessage(\`正在编辑文件: \${filePath}\`, 'bot');
|
||||
}
|
||||
|
||||
function saveFile() {
|
||||
if (!currentEditingFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
const content = fileEditorTextarea.value;
|
||||
vscode.postMessage({
|
||||
command: 'updateFile',
|
||||
filePath: currentEditingFile,
|
||||
content: content
|
||||
});
|
||||
|
||||
addMessage(\`正在保存文件: \${currentEditingFile}\`, 'user');
|
||||
cancelEdit();
|
||||
}
|
||||
|
||||
function cancelEdit() {
|
||||
currentEditingFile = null;
|
||||
fileEditorSection.classList.remove('active');
|
||||
fileEditorTextarea.value = '';
|
||||
editingFileName.textContent = '';
|
||||
}
|
||||
|
||||
window.addEventListener('message', event => {
|
||||
const message = event.data;
|
||||
|
||||
@ -281,6 +363,15 @@ export function getWebviewContent(iconUri?: string): string {
|
||||
case 'fileError':
|
||||
showError(message.error);
|
||||
break;
|
||||
case 'editFile':
|
||||
openFileEditor(message.filePath, message.content);
|
||||
break;
|
||||
case 'fileUpdated':
|
||||
addMessage(\`✅ \${message.message}: \${message.filePath}\`, 'bot');
|
||||
break;
|
||||
case 'fileUpdateError':
|
||||
addMessage(\`❌ \${message.error}\`, 'bot');
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user