CodingTrainerWeb/Scripts/app/codemirror-addon/hint-loader.js
// This gets called when a change has occured which may require hints to be updated
This gets called when a change has occured which may require hints to be updated
This gets called when a change has occured which may require hints to be updated
function checkHints(cm, key) {
        if (cm.somethingSelected()) return;
        if (key !== 'Ctrl-Space') {
            if (cm.isClean(cm.loadedHints.generation)) return;
            cm.loadedHints.generation = cm.changeGeneration();
            var noToken = ['Enter', ';', ' ', '(', ')', '{', '}', '[', ']'];
            if (noToken.indexOf(key) !== -1) return;
        }
        var token = cm.getTokenAt(cm.getCursor());
        var line = cm.getCursor().line;
        if (token.type === "string" || token.type === "number") return;
        if (token.string === ".") {
            token.start++;
            token.end = Math.max(token.start, token.end);
        }
        if (cm.loadedHints.currentToken && cm.loadedHints.currentToken.start === token.start && cm.loadedHints.currentLine === line) {
            cm.loadedHints.currentToken = token;  
            if (cm.loadedHints.currentHints) {
                filterAndShow(cm);
            } else if (key === 'Ctrl-Space') {
                cm.loadedHints.getHints(cm, cm.indexFromPos({ line: line, ch: token.start }));
            }
        } else {
            cm.loadedHints.currentToken = token;
            cm.loadedHints.currentLine = line;
            var tokenStart = token.string.length === 1 && token.string === key;
            if (key === 'Ctrl-Space' || tokenStart) {
                cm.loadedHints.getHints(cm, cm.indexFromPos({ line: line, ch: token.start }));
            }
        }
    }
function checkHints ( cm , key ) { if ( cm . somethingSelected ( ) ) return ; if ( key !== 'Ctrl-Space' ) { if ( cm . isClean ( cm . loadedHints . generation ) ) return ; cm . loadedHints . generation = cm . changeGeneration ( ) ; var noToken = [ 'Enter' , ';' , ' ' , '(' , ')' , '{' , '}' , '[' , ']' ] ; if ( noToken . indexOf ( key ) !== - 1 ) return ; } var token = cm . getTokenAt ( cm . getCursor ( ) ) ; var line = cm . getCursor ( ) . line ; if ( token . type === "string" || token . type === "number" ) return ; if ( token . string === "." ) { token . start ++ ; token . end = Math . max ( token . start , token . end ) ; } if ( cm . loadedHints . currentToken && cm . loadedHints . currentToken . start === token . start && cm . loadedHints . currentLine === line ) { cm . loadedHints . currentToken = token ; if ( cm . loadedHints . currentHints ) { filterAndShow ( cm ) ; } else if ( key === 'Ctrl-Space' ) { cm . loadedHints . getHints ( cm , cm . indexFromPos ( { line : line , ch : token . start } ) ) ; } } else { cm . loadedHints . currentToken = token ; cm . loadedHints . currentLine = line ; var tokenStart = token . string . length === 1 && token . string === key ; if ( key === 'Ctrl-Space' || tokenStart ) { cm . loadedHints . getHints ( cm , cm . indexFromPos ( { line : line , ch : token . start } ) ) ; } } }
This gets called when a change has occured which may require hints to be updated
This gets called when a change has occured which may require hints to be updated
// Don't hint if code is selected // Don't hint if the code hasn't changed since last time - the user is just navigating // These keys indicate that the token is not something we can hint: // Find the current token // Literals don't have hints // . requires hints - but not for this token, which is just . // The hints will be for the next token // Not a new hint // Because the end point will have changed // This function will ask the server for the hints, then call showHints when it has the hints // New token - get new hints if necessary // Is this the START of a new token, or has the user explicitly requested hints? // This function will ask the server for the hints, then call showHints when it has the hints