fix some bug
This commit is contained in:
@@ -124,6 +124,7 @@ document.getElementById("renameOption").onclick = () => {
|
||||
selectedItem.name = newName;
|
||||
selectedItem.div.textContent = newName;
|
||||
loadFileTree();
|
||||
showNotification('success', '文件已成功重命名!');
|
||||
});
|
||||
|
||||
}
|
||||
@@ -146,6 +147,7 @@ document.getElementById("copyOption").onclick = () => {
|
||||
if (selectedItem) {
|
||||
copiedItem = selectedItem;
|
||||
console.log("Item copied:", copiedItem);
|
||||
showNotification('info', '文件已成功复制!');
|
||||
}
|
||||
hideContextMenu();
|
||||
};
|
||||
@@ -160,7 +162,7 @@ document.getElementById("pasteOption").onclick = (event) => {
|
||||
newPath = selectedItem.path;
|
||||
}
|
||||
fetch(`/vsc-like/copy-files`, { method: 'POST', body: JSON.stringify({ oldPath: copiedItem.path+'/'+copiedItem.name, newPath: newPath }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {loadFileTree();showNotification('success', '文件已成功粘贴!')});
|
||||
console.log("Item pasted:", selectedItem);
|
||||
}
|
||||
hideContextMenu();
|
||||
@@ -172,7 +174,7 @@ document.getElementById("deleteOption").onclick = (event) => {
|
||||
if (confirm("Are you sure you want to delete selected file/folder?")) {
|
||||
if (selectedItem) {
|
||||
fetch(`/vsc-like/delete-file`, { method: 'POST', body: JSON.stringify({ path: selectedItem.path+'/'+selectedItem.name }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {loadFileTree();showNotification('success', '文件已成功删除!')});
|
||||
}
|
||||
}
|
||||
hideContextMenu();
|
||||
@@ -257,6 +259,8 @@ function loadFileContent(item) {
|
||||
editor.setValue(data.content);
|
||||
}
|
||||
});
|
||||
// 设置编辑器语言
|
||||
setEditorLanguageBasedOnFile(item.name);
|
||||
// code-like 打开文件
|
||||
ChangeActiveTextEditor(item.path+'/'+item.name);
|
||||
}
|
||||
@@ -278,15 +282,15 @@ function createNewFile(event) {
|
||||
if (selectedItem) {
|
||||
if (selectedItem.type === 'directory') {
|
||||
fetch(`/vsc-like/create-file`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: selectedItem.path+'/'+selectedItem.name }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {loadFileTree();showNotification('success', '文件已成功创建!')});
|
||||
} else {
|
||||
console.log("selectedItem.path",selectedItem.path);
|
||||
fetch(`/vsc-like/create-file`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: selectedItem.path }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {loadFileTree();showNotification('success', '文件已成功创建!')});
|
||||
}
|
||||
}else{
|
||||
fetch(`/vsc-like/create-file`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: '.' }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {loadFileTree();showNotification('success', '文件已成功创建!')});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,21 +303,48 @@ function createNewFolder(event) {
|
||||
if (folderName) {
|
||||
if (selectedItem) {
|
||||
if (selectedItem.type === 'directory') {
|
||||
fetch(`/vsc-like/create-folder`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: selectedItem.path+'/'+selectedItem.name }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
fetch(`/vsc-like/create-folder`, { method: 'POST', body: JSON.stringify({ path: folderName, parent: selectedItem.path+'/'+selectedItem.name }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => {loadFileTree();showNotification('success', '文件夹已成功创建!')});
|
||||
} else {
|
||||
fetch(`/vsc-like/create-folder`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: selectedItem.path }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
fetch(`/vsc-like/create-folder`, { method: 'POST', body: JSON.stringify({ path: folderName, parent: selectedItem.path }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => {loadFileTree();showNotification('success', '文件夹已成功创建!')});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 触发保存成功时按钮的动画
|
||||
function triggerSaveAnimation() {
|
||||
const saveButton = document.getElementById('saveBtn');
|
||||
|
||||
// 先清除已有的动画类
|
||||
saveButton.classList.remove('bounce-animation', 'bigger-color');
|
||||
|
||||
// 添加新的动画类
|
||||
saveButton.classList.add('bounce-animation', 'bigger-color');
|
||||
|
||||
// 动画完成后移除动画类(确保可以重复触发动画)
|
||||
setTimeout(() => {
|
||||
saveButton.classList.remove('bounce-animation', 'bigger-color');
|
||||
}, 500); // 500ms后移除动画
|
||||
}
|
||||
|
||||
function postSaveFile(path, content){
|
||||
|
||||
fetch(`/vsc-like/save-file`, { method: 'POST', body: JSON.stringify({ path: path, content: content }) , headers: { 'Content-Type': 'application/json' } })
|
||||
.then(() => loadFileTree());
|
||||
.then(() => {
|
||||
loadFileTree();
|
||||
triggerSaveAnimation(); // 触发按钮动画
|
||||
showNotification('success', '文件已成功保存!');
|
||||
});
|
||||
}
|
||||
document.addEventListener('keydown', function(event) {
|
||||
// 检查是否按下Ctrl+S
|
||||
if (event.ctrlKey && event.key === 's') {
|
||||
event.preventDefault(); // 阻止默认的保存操作
|
||||
postSaveFile(selectedItem.path+'/'+selectedItem.name, editor.getValue()); // 手动保存
|
||||
}
|
||||
});
|
||||
|
||||
// 保存文件
|
||||
function saveFile(event) {
|
||||
|
||||
Reference in New Issue
Block a user