fix: fall back to plain text for unsupported editor modes

This commit is contained in:
Thomas Durieux committed 2026-10-07 12:24:21 +00:00
1 parent d68c9e6106
commit 64ae393200
6 files changed
+23 -7

No files matched your search

+3 -1
View File
@@ -97,7 +97,9 @@ export const codeEditor = {
beforeUnmount(el) { el._editorDisposed = true; el._editor?.destroy(); },
};
function applyEditorOptions(el, options = {}) {
if (options.mode) el._editor.session.setMode("ace/mode/" + options.mode);
const modes = window.ace.require("ace/ext/modelist").modesByName;
const mode = Object.hasOwn(modes, options.mode) ? options.mode : "text";
el._editor.session.setMode("ace/mode/" + mode);
if (options.theme) el._editor.setTheme("ace/theme/" + options.theme);
el._editor.setReadOnly(options.readOnly !== false);
}