summaryrefslogtreecommitdiff
path: root/js/codeq/editor.js
blob: f84bd059f70a4265938c86e421d114f66b8a2cc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
codeq.makeEditor = function (elt, options) {
    var statusBar = document.createElement("div"),
        updateStatusBar = function (pos) {
            statusBar.innerHTML = 'line ' + (pos.line+1) + ', column ' + (pos.ch+1);
        },
        editor;

    options.cursorHeight = 0.85;
    options.lineNumbers = true;
    options.matchBrackets = true;
    options.extraKeys = {
        // replace tabs with spaces
        Tab: function (cm) {
            var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
            cm.replaceSelection(spaces);
        }
    };
    editor = CodeMirror(elt, options),

    //since addPanel brakes CodeMirrot responsiveness no mather what, we manually added block-statusbar located at the bottom of editor block
    //statusBar.className = 'editor-statusbar';
    statusBar = statusBar = $(elt).siblings(".block-statusbar")[0];
    updateStatusBar({line: 0, ch: 0});

    //editor.addPanel(statusBar, {position: 'bottom'});
    editor.on('cursorActivity', function (instance) {
        var pos = instance.getDoc().getCursor();
        updateStatusBar(pos);
    });

    return editor;
};