[Codemirror] How can I implement to change mode dynamically?
Closed this issue · 1 comments
KojiIzawa commented
I'd like to use codemirror-editor of this. And the Codemirror provides the functionality to change highlight mode, which use setOption() and autoLoadMode() function. I try to add code as below on codemirror.js
.
modeChange:function(modeName){
rtn = CodeMirror.findModeByName(modeName);
this._editor.setOption("mode", rtn.mime); // 'text/css'
this._editor.refresh();
CodeMirror.autoLoadMode(this._editor, rtn.mode);
},
But I encounter ReferenceError: CodeMirror is not defined
. How can I realize to change mode dynamically?
mkozhukh commented
You can use
$$("codemirror").getEditor(true).then(function(editor){
//do anything with editor
});
The code of codemirror is included dynamically, so you need to wait for the above promise to resolve, before executing any CodeMirror related logic.