Skip to content Skip to sidebar Skip to footer

Codemirror Keeps Appending When Language Dropdown Is Selected

I am using CodeMirror to provie syntax highlighting for a little project to save programming departments code bits. The asp-mvc page consists of a textxt, a dropdown list for langu

Solution 1:

You only need to call fromTextArea ONCE ever (per text area).

So create it, store it off, and use it if you need to change anything later.

var cmInstance = $('#code').data('CodeMirrorInstance');

if (!cmInstance)
{
    cmInstance = CodeMirror.fromTextArea(document.getElementById("code"),
    {
        lineNumbers: lines,
        matchBrackets: match,
        mode: mode
    });
    $('#code').data('CodeMirrorInstance', cmInstance);
}



//latervar cm = $('#code').data('CodeMirrorInstance');
cm.whateverYouWantToDoToCodeMirror();

Post a Comment for "Codemirror Keeps Appending When Language Dropdown Is Selected"