Sha256: 0fb6370cbd09f114ddd9e178bca2a86af75e536b7ffd5409081919a673ea282f

Contents?: true

Size: 1.2 KB

Versions: 170

Compression:

Stored size: 1.2 KB

Contents

function registerAutocomplete(mode, keywords, identifierRegex) {

    var regex = identifierRegex || /[a-zA-Z_$][a-zA-Z0-9_$]*\b/;

    function isIdentifier(name) {
        return regex.test(name.trim());
    }

    CodeMirror.registerHelper('hint', mode, function (editor, options) {
        var WORD = /[\w$]+/;

        var word = options && options.word || WORD;
        var cur = editor.getCursor();
        var curLine = editor.getLine(cur.line);
        var end = cur.ch;
        var start = end;

        var words = {};
        editor.getValue().split(/([^a-zA-Z0-9_$])|[\[\]{}() \n\t]/).concat(keywords).forEach(function (name) {
            if (isIdentifier(name)) words[name.trim()] = true;
        });

        while (start && word.test(curLine.charAt(start - 1))) --start;

        var curWord = curLine.slice(start, end);

        var list = [];

        for (var aWord in words) {
            if (aWord.toLowerCase().indexOf(curWord.toLowerCase()) === 0) {
                list.push(aWord);
            }
        }

        list.sort && list.sort();

        return {
            list: list,
            from: CodeMirror.Pos(cur.line, start),
            to: CodeMirror.Pos(cur.line, end)
        };
    });

}

Version data entries

170 entries across 170 versions & 1 rubygems

Version Path
mumuki-laboratory-5.10.1 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.10.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.9.1 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.9.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.8.3 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.8.1 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.8.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.7.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.6.3 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.6.2 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.6.1 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.6.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.5.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.4.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.3.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.2.1 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.2.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.1.1 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.1.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-5.0.12 vendor/assets/javascripts/codemirror-modes/autocomplete.js