var words = {
	plus : "",
	minus : "",
	multiplyBy: "",
	divideBy: ""
}

function getRelevantWords(word)
{
	var wordArray = Object.getOwnPropertyNames(words);
	var relevantWords = [];
	for(var i = 0; i < wordArray.length; i++)
	{
		if(wordArray[i].toLowerCase().substr(0, word.length) == word.toLowerCase())
		{
			relevantWords.push(wordArray[i]);
		}
	}
	return relevantWords;
}

function optionString(item)
{
	return "<div class='ac-option' value='" + item + "'>" + item + "</div>";
}

function fullOptionString(items)
{
	var result = "";
	
	for(var i = 0; i < items.length; i++)
	{
		result += optionString(items[i]);
	}
	return result;
}

function autoComplete()
{
	$("#math-words").removeClass("hidden");
	
	var typedText = $("textarea").val();
	
	var relevantWord =  typedText.split(' ').pop();
	
	$("#math-words").html( fullOptionString( getRelevantWords(relevantWord) ));
}

function SetCursorEnd(tID) {
    tID += "";
    $(tID).focus();
    var t = $(tID).val();
    if (t.length == 0) { return; }
    $(tID).val("");
    $(tID).val(t);
    $(tID).scrollTop($(tID)[0].scrollHeight); 
}

function replaceText(replacementText)
{
	var typedText = $("textarea").val();
	var index = typedText.lastIndexOf(" ");
	if(index == null || index == undefined)	{
		index = 1;
	}
	var resultText = typedText.substr(0, index) + " " + replacementText;
	$("textarea").val(resultText);
	SetCursorEnd("#code-text");
}

$('body').on('click', '.ac-option', function() {
	replaceText($(this).text());
});

$('textarea').on( 'keydown', function( e ) {
    if( e.which == 9 ) {
    	e.preventDefault();
        console.log( e.target.href );
        
        replaceText($($(".ac-option")[0]).text());
    }
} );

@@ -401,19 +401,145 @@
 ing(item
-)%0A%7B
+, classText)%0A%7B%0A%09var selectedString = %22%22;%0A%09%0A%09if(classText != null && classText != undefined)%0A%09%7B%0A%09%09selectedString = classText;%0A%09%7D%0A%09
 %0A%09return
@@ -561,16 +561,39 @@
 c-option
+ %22 + selectedString + %22
 ' value=
@@ -729,16 +729,82 @@
 ++)%0A%09%7B%0A%09
+%09if(i == 0)%7B result += optionString(items%5Bi%5D, selected) %7D;%0A%09%09else%7B
 %09result 
@@ -829,16 +829,18 @@
 ems%5Bi%5D);
+ %7D
 %0A%09%7D%0A%09ret
@@ -1868,18 +1868,16 @@
 eText($(
-$(
 %22.ac-opt
@@ -1883,13 +1883,18 @@
 tion
-%22)%5B0%5D
+.selected%22
 ).te

Update autocomplete.js