Search code examples
codemirror

How to dynamically switch modes with CodeMirror?


How to dynamically switch modes with CodeMirror?

I have the default set, but need to switch it.


Solution

  • Something like this would help you.

    First, set CodeMirror:

    this.editor = CodeMirror.fromTextArea(document.getElementById("textAreaCodeMirror"), {
        lineNumbers: true,
        matchBrackets: true,
        styleActiveLine: true,
        theme:"eclipse",
        mode:language
    });
    

    Then, to change the mode

    this.editor.setOption("mode", language);