fix some bug
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||
|
||||
<link rel="stylesheet" href="/vsc-like/static/css/index.css">
|
||||
<link rel="stylesheet" href="/vsc-like/static/css/notification.css">
|
||||
<script src="/vsc-like/static/js/notification.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
@@ -57,7 +59,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="notificationsContainer"></div>
|
||||
|
||||
<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>
|
||||
@@ -72,11 +74,47 @@
|
||||
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' } });
|
||||
let saveTimeout=null;
|
||||
// 语言映射表,文件后缀与Monaco语言之间的映射
|
||||
const languageMap = {
|
||||
'.js': 'javascript',
|
||||
'.ts': 'typescript',
|
||||
'.html': 'html',
|
||||
'.css': 'css',
|
||||
'.json': 'json',
|
||||
'.java': 'java',
|
||||
'.py': 'python',
|
||||
'.cpp': 'cpp',
|
||||
'.c': 'c',
|
||||
'.go': 'go',
|
||||
'.ruby': 'ruby',
|
||||
'.php': 'php',
|
||||
'.xml': 'xml',
|
||||
'.sql': 'sql',
|
||||
'.sh': 'shell',
|
||||
'.yaml': 'yaml',
|
||||
'.md': 'markdown',
|
||||
'.txt': 'plaintext',
|
||||
};
|
||||
|
||||
// 缺省语言
|
||||
const defaultLanguage = 'plaintext';
|
||||
function getFileExtension(filename) {
|
||||
return filename.slice(((filename.lastIndexOf(".") - 1) >>> 0) + 2);
|
||||
}
|
||||
|
||||
// 根据文件名设置语言
|
||||
function setEditorLanguageBasedOnFile(filename) {
|
||||
const fileExtension = '.' + getFileExtension(filename).toLowerCase();
|
||||
const language = languageMap[fileExtension] || defaultLanguage; // 如果没有匹配,使用默认语言
|
||||
|
||||
// 设置Monaco Editor语言
|
||||
editor.setModel(monaco.editor.createModel(editor.getModel().getValue(), language));
|
||||
console.log(`Editor language set to: ${language}`);
|
||||
}
|
||||
require(['vs/editor/editor.main'], function() {
|
||||
editor = monaco.editor.create(document.getElementById('editorContainer'), {
|
||||
value: '',
|
||||
language: 'javascript'
|
||||
});
|
||||
|
||||
const fileTreeDiv = document.getElementById('fileTreeContent');
|
||||
@@ -88,6 +126,10 @@
|
||||
|
||||
// 监听文本编辑事件
|
||||
editor.onDidChangeModelContent(event => {
|
||||
if (!selectedItem){
|
||||
showNotification('warning', '未选中文件,修改将不会保存');
|
||||
return;
|
||||
}
|
||||
const filePath = selectedItem.path + '/' +selectedItem.name;
|
||||
const changes = event.changes;
|
||||
console.log("changes",changes)
|
||||
@@ -114,6 +156,11 @@
|
||||
config: code_like_config,
|
||||
}, 5000
|
||||
);
|
||||
// saveFile
|
||||
if (saveTimeout) clearTimeout(saveTimeout);
|
||||
saveTimeout = setTimeout(() => {
|
||||
postSaveFile(selectedItem.path+'/'+selectedItem.name, editor.getValue());
|
||||
}, 5000); // 5000ms = 5秒
|
||||
});
|
||||
|
||||
// 监听粘贴事件
|
||||
@@ -161,23 +208,6 @@
|
||||
}else{
|
||||
document.getElementById('terminal').style.display = 'none';
|
||||
}
|
||||
// event.stopPropagation();
|
||||
// const terminalDiv = document.getElementById('terminal');
|
||||
// terminalDiv.style.display = (terminalDiv.style.display === 'none' || terminalDiv.style.display === '') ? 'block' : 'none';
|
||||
// if (socket == null) {
|
||||
// socket = io.connect('http://' + document.domain + ':5200/vsc-like/terminal');
|
||||
// }
|
||||
// socket.on('connected', function(data) {
|
||||
// console.log('Terminal connected');
|
||||
// });
|
||||
// socket.on('terminal_output', function(data) {
|
||||
// const terminalDiv = document.getElementById('terminal');
|
||||
// terminalDiv.textContent += data.data;
|
||||
// });
|
||||
|
||||
// function sendTerminalInput(input) {
|
||||
// socket.emit('send_input', { input: input });
|
||||
// }
|
||||
}
|
||||
|
||||
// 按钮绑定事件
|
||||
|
||||
Reference in New Issue
Block a user