Esempio n. 1
0
    BShints.prototype.hasHints = function (editor, implicitChar) {
        this.editor = editor;
        var cursor = this.editor.getCursorPos();

        if (cursor.line !== this.lastLine) {
            var rawWordList = bsfuncHint.match(this.tokenDefinition);
            this.cachedWordList = [];
            var i;
            for (i = 0; i < rawWordList.length; i++) {
                var word = rawWordList[i];
                if (this.cachedWordList.indexOf(word) === -1) {
                    this.cachedWordList.push(word);
                }
            }
        }
        this.lastLine = cursor.line;

        var lineBeginning = {
            line: cursor.line,
            ch: 0
        };
        var textBeforeCursor = this.editor.document.getRange(lineBeginning, cursor);
        var symbolBeforeCursorArray = textBeforeCursor.match(this.currentTokenDefinition);
        if (symbolBeforeCursorArray) {
            var n;
            for (n = 0; n < this.cachedWordList.length; n++) {
                if (this.cachedWordList[n].indexOf(symbolBeforeCursorArray[0]) === 0) {
                    return true;
                }
            }
        }
        return false;
    };
Esempio n. 2
0
    BShints.prototype.hasHints = function (editor, implicitChar) {
        this.editor = editor;
        var cursor = this.editor.getCursorPos();

        // if it is not the same line as the last input - rebuild word list
        if (cursor.line !== this.lastLine) {
            var rawWordList = bsfuncHint.match(this.tokenDefinition);
            this.cachedWordList = [];
            var i;
            for (i = 0; i < rawWordList.length; i++) {
                var word = rawWordList[i];
                if (this.cachedWordList.indexOf(word) === -1) {
                    this.cachedWordList.push(word);
                }
            }
        }
        this.lastLine = cursor.line;

        // if has entered more than 2 characters - start completion
        var lineBeginning = {
            line: cursor.line,
            ch: 0
        };
        var textBeforeCursor = this.editor.document.getRange(lineBeginning, cursor);
        var symbolBeforeCursorArray = textBeforeCursor.match(this.currentTokenDefinition);
        if (symbolBeforeCursorArray) {
            // find if the half-word inputed is in the list
            var n;
            for (n = 0; n < this.cachedWordList.length; n++) {
                if (this.cachedWordList[n].indexOf(symbolBeforeCursorArray[0]) === 0) {
                    return true;
                }
            }
        }
        return false;
    };