function collapseAll() {
        var editor = EditorManager.getFocusedEditor();
        if (editor) {
            var cm = editor._codeMirror;
            CodeMirror.commands.foldToLevel(cm);
        }
    }
Collapses all foldable regions in the current document. Folding is done up to a level 'n'
which is defined in the `maxFoldLevel` preference. Levels refer to fold heirarchies e.g., for the following
code fragment, the function is level 1, the if statement is level 2 and the forEach is level 3

    function sample() {
        if (debug) {
            logMessages.forEach(function (m) {
                console.debug(m);
            });
        }
    }