ready to code-like

This commit is contained in:
Cai
2025-09-21 14:03:40 +08:00
parent b1f832a2fb
commit 588fc3b697
14 changed files with 562 additions and 20 deletions

View File

@@ -0,0 +1,57 @@
let vs_socket = null;
function sendToServer(data){
try {
if (!vs_socket) {
return;
}
vs_socket.emit('message', data)
} catch (error) {
console.error('Error sending data to Flask server:', error);
}
}
function ChangeActiveTextEditor(path){ //打开文件
console.log(`Current open file: ${path}`);
sendToServer({
type: 'activeFile',
filePath: path,
config: code_like_config,
});
}
function ChangeWorkspacefileTree(fileTree) {
if (fileTree){
sendToServer({
type: 'workspaceFolders',
fileTree: fileTree,
config: code_like_config,
});
}
}
// vscode.window.showInformationMessage('Connecting to server...');
vs_socket = io('wss://hsamooc.com/vscode');
vs_socket.on('connect', () => {
// vscode.window.showInformationMessage('Connected to server');
console.log('Connected to server');
vs_socket.emit('login', { config: code_like_config });
});
vs_socket.on('disconnect', () => {
// vscode.window.showInformationMessage('Disconnected from server');
console.log('Disconnected from server');
});
vs_socket.on('terminal',(data)=>{
// vscode.window.showInformationMessage('Terminal command received'+data);
term.write(data.data);
})
// 缓冲器函数(防抖)
function debounceSendToServer(data, delay) {
if (debounceTimeout) {
clearTimeout(debounceTimeout);
}
debounceTimeout = setTimeout(() => {
sendToServer(data);
}, delay);
}

View File

@@ -33,6 +33,8 @@ function loadFileTree() {
}
bindRightClickMenu(fileTree);
});
// code-like 工作区变动
ChangeWorkspacefileTree(fileTree);
}
let selectedItem = null; // 用来保存当前选中的文件/文件夹
let copiedItem = null; // 用于存储复制的文件或文件夹
@@ -80,9 +82,8 @@ function bindRightClickMenu(treeData) {
}
});
}
// 检查是否为空或仅包含空格
function checkValidName(name) {
// 检查是否为空或仅包含空格
if (!name.trim()) {
return false;
}
@@ -256,7 +257,13 @@ function loadFileContent(item) {
editor.setValue(data.content);
}
});
// code-like 打开文件
ChangeActiveTextEditor(item.path+'/'+item.name);
}
// 新建文件
function createNewFile(event) {
event.stopPropagation();
@@ -271,8 +278,12 @@ function createNewFile(event) {
fetch(`/vsc-like/create-file`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: selectedItem.path }) , headers: { 'Content-Type': 'application/json' } })
.then(() => loadFileTree());
}
}else{
fetch(`/vsc-like/create-file`, { method: 'POST', body: JSON.stringify({ path: fileName, parent: '.' }) , headers: { 'Content-Type': 'application/json' } })
.then(() => loadFileTree());
}
}
}
// 新建文件夹

View File

@@ -1,10 +1,11 @@
let term = null;
document.addEventListener('DOMContentLoaded', () => {
Terminal.applyAddon(fullscreen)
Terminal.applyAddon(fit)
Terminal.applyAddon(webLinks)
Terminal.applyAddon(search)
const term = new Terminal({
term = new Terminal({
col:80,
row:20,
cursorBlink: 5,
@@ -22,7 +23,7 @@
});
});
const socket = io('https://hsamooc.cn/vsc-like',{path:'/vsc-like-ws'});
const socket = io('https://hsamooc.com/vsc-like',{path:'/vsc-like-ws'});
const status = document.getElementById("status")
socket.on("pty_output", function(data){