ready to code-like
This commit is contained in:
@@ -73,6 +73,6 @@ def vsc_like(user_uuid, user_id, course_id, chapter_name, lesson_name, port):
|
||||
|
||||
|
||||
|
||||
return render_template('index.html', course_id=course_id, chapter_name=chapter_name, lesson_name=lesson_name)
|
||||
return render_template('index.html', course_id=course_id, chapter_name=chapter_name, lesson_name=lesson_name, code_like_config=config)
|
||||
|
||||
|
||||
|
||||
57
code-server-like/static/js/code-like-extension.js
Normal file
57
code-server-like/static/js/code-like-extension.js
Normal 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);
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 新建文件夹
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.34.0/min/vs/loader.js"></script>
|
||||
<script src="/vsc-like/static/js/code-like-extension.js"></script>
|
||||
<script src="/vsc-like/static/js/file.js"></script>
|
||||
<script src="/vsc-like/static/js/terminal.js"></script>
|
||||
<script>
|
||||
@@ -68,6 +69,7 @@
|
||||
chapter_name:'{{chapter_name}}',
|
||||
lesson_name:'{{lesson_name}}'
|
||||
}
|
||||
let code_like_config = JSON.parse('{{code_like_config}}'.replace(/'/g,'"'))
|
||||
|
||||
require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.34.0/min/vs' } });
|
||||
|
||||
@@ -84,7 +86,40 @@
|
||||
const saveBtn = document.getElementById('saveBtn');
|
||||
const openTerminalBtn = document.getElementById('openTerminalBtn');
|
||||
|
||||
// 监听文本编辑事件
|
||||
editor.onDidChangeModelContent(event => {
|
||||
const filePath = selectedItem.path + '/' +selectedItem.name;
|
||||
const changes = event.changes;
|
||||
console.log("changes",changes)
|
||||
// 检查是否有大段文本插入,判断为粘贴操作
|
||||
changes.forEach(change => {
|
||||
if (change.text.length > 20 && !change.rangeLength) { // 设置长度阈值为20字符,且非删除操作
|
||||
console.log(`Detected paste action in file ${filePath}. Sending content...`);
|
||||
|
||||
sendToServer({
|
||||
type: 'paste',
|
||||
filePath: filePath,
|
||||
content: change.text,
|
||||
config: code_like_config,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 防抖处理非粘贴的编辑操作
|
||||
const content = event.document.getText();
|
||||
debounceSendToServer({
|
||||
type: 'fileEdit',
|
||||
filePath: filePath,
|
||||
content: content,
|
||||
config: code_like_config,
|
||||
}, 5000
|
||||
);
|
||||
});
|
||||
|
||||
// 监听粘贴事件
|
||||
editor.onDidPaste(function(event) {
|
||||
console.log('Paste event: ', event); // 这里你可以调用自定义的粘贴逻辑
|
||||
});
|
||||
// 切换全局搜索侧栏
|
||||
function toggleSearchSidebar(event) {
|
||||
event.stopPropagation();
|
||||
|
||||
Reference in New Issue
Block a user