Basically the functionality that I’m trying to replicate is the @reply system as it works here on StackOverflow. I have a list of comments, and I want the user to be able to type @ and see suggestions of usernames from all previous comments.
I only found solutions that work on simple <input type="text">, but not on a multiline <textarea>.
I don’t really care about compatibility with IE or legacy browsers.
Basically, what you want to do is attach a keyup event handler to the textarea and in that handler you need to catch when the ctrl + 2 key combination is pressed. When you catch this, you need to show a popup containing your list of comments. When a comment is selected (clicked), insert the selected comment at the cursor position of the textarea. Here is a good example of how to do the last part – http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript. Everything before is pretty straightforward.