summaryrefslogtreecommitdiff
path: root/js/codeq/editor.js
blob: d0b365e30ea97daa0aa0d57ca72f640ab2a12900 (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
codeq.makeEditor = function (elt, options) {
    var statusBar = $(elt).siblings(".block-statusbar")[0],
        updateStatusBar = function (pos) {
            statusBar.innerHTML = 'line ' + (pos.line+1) + ', column ' + (pos.ch+1);
        },
        allOptions = $.extend({
            cursorHeight: 0.85,
            lineNumbers: true,
            matchBrackets: true,
            extraKeys: {
                // replace tabs with spaces
                Tab: function (cm) {
                    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
                    cm.replaceSelection(spaces);
                }
            }
        }, options),
        editor = CodeMirror(elt, allOptions);

    updateStatusBar({line: 0, ch: 0});
    editor.on('cursorActivity', function (instance) {
        var pos = instance.getDoc().getCursor();
        updateStatusBar(pos);
    });

    return editor;
};