git-sync-web 自动提交 2026-09-09 16:33:32
This commit is contained in:
+1145
-1196
File diff suppressed because it is too large
Load Diff
+25
-29
@@ -1,29 +1,25 @@
|
||||
// CodeMirror 引导:在 codemirror.min.js 及其 mode 加载完成后接管 #file-editor。
|
||||
// 若库未加载或初始化失败,window.Editor.cm 保持 null,自动回退原生 textarea,功能不受影响。
|
||||
(function () {
|
||||
if (typeof window.CodeMirror === 'undefined' || typeof window.Editor === 'undefined') return;
|
||||
var ta = document.getElementById('file-editor');
|
||||
if (!ta) return;
|
||||
try {
|
||||
var dark = document.documentElement.classList.contains('dark');
|
||||
var cm = window.CodeMirror.fromTextArea(ta, {
|
||||
lineNumbers: true,
|
||||
lineWrapping: true,
|
||||
indentUnit: 2,
|
||||
tabSize: 2,
|
||||
theme: dark ? 'material-darker' : 'eclipse',
|
||||
readOnly: ta.disabled ? 'nocursor' : false,
|
||||
extraKeys: {
|
||||
'Ctrl-S': function () { if (window.Editor.onSave) window.Editor.onSave(); },
|
||||
'Cmd-S': function () { if (window.Editor.onSave) window.Editor.onSave(); }
|
||||
}
|
||||
});
|
||||
window.Editor.cm = cm;
|
||||
// CodeMirror 的 change 事件桥接到草稿缓存
|
||||
cm.on('change', function () { if (window.Editor.onChange) window.Editor.onChange(); });
|
||||
// 模式跟随打开文件时的 setMode
|
||||
var cur = window.Editor.value;
|
||||
} catch (e) {
|
||||
if (window.console) console.warn('CodeMirror 初始化失败,已回退原生编辑器:', e);
|
||||
}
|
||||
})();
|
||||
(function () {
|
||||
if (typeof window.CodeMirror === 'undefined' || typeof window.Editor === 'undefined') return;
|
||||
var ta = document.getElementById('file-editor');
|
||||
if (!ta) return;
|
||||
try {
|
||||
var dark = document.documentElement.classList.contains('dark');
|
||||
var cm = window.CodeMirror.fromTextArea(ta, {
|
||||
lineNumbers: true,
|
||||
lineWrapping: true,
|
||||
indentUnit: 2,
|
||||
tabSize: 2,
|
||||
theme: dark ? 'material-darker' : 'eclipse',
|
||||
readOnly: ta.disabled ? 'nocursor' : false,
|
||||
extraKeys: {
|
||||
'Ctrl-S': function () { if (window.Editor.onSave) window.Editor.onSave(); },
|
||||
'Cmd-S': function () { if (window.Editor.onSave) window.Editor.onSave(); }
|
||||
}
|
||||
});
|
||||
window.Editor.cm = cm;
|
||||
cm.on('change', function () { if (window.Editor._suspend) return; if (window.Editor.onChange) window.Editor.onChange(); });
|
||||
var cur = window.Editor.value;
|
||||
} catch (e) {
|
||||
if (window.console) console.warn('CodeMirror 初始化失败,已回退原生编辑器:', e);
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user