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-9.23.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.22.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.21.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.20.1 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.20.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.19.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.18.1 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.18.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.17.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.16.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.15.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.14.1 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.14.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.13.2 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.13.1 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.13.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.12.1 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.12.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.11.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js
mumuki-laboratory-9.10.0 vendor/assets/javascripts/codemirror-modes/autocomplete.js