Files

26 lines
991 B
JavaScript

(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);
}
})();