Well, it's not certainly not that simple, but here's how I would approach this problem.
First of all, take a very good look at the jQuery UI autocomplete plugin's documentations page. The solution here would be a combination of those.
You'll want to store the last character entered by the user in a variable, then check on autocompletesearch
to see if the characters the user is currently entering is after an @
and before another whitespace character, and canceling the search by returning false if the condition is not met.
Next the source
for the autocomplete will need to be a custom callback that processes the current content of the textarea
for what the user has already typed after the @
and search through your array for matches to that name.
Finally, the autocompleteselect
event will need to be modified to insert in the names in the correct positions after the user has chosen the name. The autocompletefocus
event will also have to be suppressed for this to work. You'll want to have a look at the Multiple Tags and the combobox examples for this.