Working on tab autocomplete
Working on tab autocomplete

Previously autocomplete did not completely overwrite the word, but
only up to the caret.  This resulted in replacements stacking up,
which looked strange and was incorrect behavior.  Now the replacement
checks for the entire word, and this results in the expected
behavior.

This also moves some of the variables off of the AngularJS scope.
Not all of the data needs to be on the scope, so this prevents
leaking of data which can remain within the local JS scope.

Autocompletion works as intended if the caret is placed at or within
the last word.  It also works as intended if the caret is placed
within the word that should be processed, or at the begining of the
word.  If the caret is placed at the end of the word, the word
proceeding the caret is processed.  This is incorrect behavior.
Fixed off-by-one issue

The off-by-one issue that caused words to not be processed if the
caret was at the end was fixed.  The issue was caused by the check
for the word start, which looks for the nearest space character.
If the caret is next to the closest space, it is skipped because
the check starts after it.  By subtracting one from the caret
position before doing the check, the correct word was picked up
at all of the needed locations.

This also cleans up the function that filters the users when looking
for matches.
Update the caret position on click and focus
Fixed match processing

Before when the text box was clicked, only the word start and end
were updated.  This meant that hitting tab at this point would be
using the wrong set of matches.  This fixes that by just binding
the click and focus events to the keydown handler and everything
works as expected.
Merge pull request #32 from coldstorm/tab-autocomplete

Implement tab autocomplete [Closes #3]