Hi there,
I'm trying to create a plugin that looks for the user typing "@username", and displays a dropdown list of users in the system for possible auto-complete.
My current question is this - what is the best/correct way to get the current word after the user types something? Here is my current strategy:
I guess when I bullet it out like that, it doesn't seem too complex, but travelling around adjacent text nodes is what seems like there would already be a method for. I tried range.expand(), but that went all the way to the block level, and I just need the word. Is there a built-in function or mechanism that would be better to use?
My over-arching question is this - is there a plugin like this that already exists? I couldn't find anything, but it is common enough in many of todays large web applications (such as Jive), that it seems like it would have been done before.
Any help of guidance is greatly appreciated. Thanks!
-Sean
I'm trying to create a plugin that looks for the user typing "@username", and displays a dropdown list of users in the system for possible auto-complete.
My current question is this - what is the best/correct way to get the current word after the user types something? Here is my current strategy:
- Listen for the "key" event
- Get the current range
- If the range is collapsed, travel backwards finding non-whitespace
- Check adjacent nodes if whitespace hasn't been found, and if they are text nodes, continue building the word to search for
I guess when I bullet it out like that, it doesn't seem too complex, but travelling around adjacent text nodes is what seems like there would already be a method for. I tried range.expand(), but that went all the way to the block level, and I just need the word. Is there a built-in function or mechanism that would be better to use?
My over-arching question is this - is there a plugin like this that already exists? I couldn't find anything, but it is common enough in many of todays large web applications (such as Jive), that it seems like it would have been done before.
Any help of guidance is greatly appreciated. Thanks!
-Sean
