How do I add code folding for VB in CodeMirror?

Can anyone tell me how to get code folding working for vb (.net) mode in the CodeMirror javascript code editor? I have minimal experience with javascript and I cannot seem to find the answer in the user manual. I would like it to fold classes, modules, functions, subs and comments ideally but would be happy if it just folds based upon indentation.

Upvotes: 2

Views: 1851

Answers (1)

Found the following javascript for the foldGutter property of the CodeMirror.fromTextArea function elsewhere on StackFlow. Works well.

foldGutter: {
    rangeFinder: new CodeMirror.fold.combine(CodeMirror.fold.indent, CodeMirror.fold.comment)
}

So the <script> element on my web page now looks like this.

<script id="script">
    window.onload = function () {
        var te = document.getElementById("codeEd");
        window.editor = CodeMirror.fromTextArea(te, {
            mode: "text/x-vb",
            styleActiveLine: true,
            lineNumbers: true,
            lineWrapping: false,
            extraKeys: { "Ctrl-Q": function (cm) { cm.foldCode(cm.getCursor()); } },
            foldGutter: {
                rangeFinder: new CodeMirror.fold.combine(CodeMirror.fold.indent, CodeMirror.fold.comment)
            },
            gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
        });
        editor.setSize("100%","100%");
    };
</script>

Thanks to aaldim

Upvotes: 5

Related Questions