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

@@ -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(/&#39;/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();