AutoCompleter: Better performance using text areas #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Autocompleter is designed to send constantly Ajax requests while you are filling in a field to get the results that fit the input. And so it should work in most cases.
But there is a case where this is not desirable: when you are filling a text area where not every token requires auto-completion. As an example you have the “What’s happening?” box on Twitter. You can enter any text, but if you type a “@” the Autocompleter is activated to look for your friends.
In my application I have a similar box, and I need Autocompleter to run only when a user types a “#” (for tags) or a “:” (for special keywords). If Autocompleter were always running and a lot of users were writing at a time, the server performance would be seriously impaired.
So I have added support for a regexp option. If it exists, Ajax requests are done only if the token matches with the regexp pattern. E.g. regexp: /(#|:)(\w)*/ would activate Ajax requests for tokens that start with ‘#’ or ‘:’.
What do you think?