I'd like to design for a text input control that automatically converts text matching an arbitrary pattern into "tokens," and then allows users to interact with those tokens as if they were text glyphs.
In other words, once those tokens are created, users can click them to select them, or drag over them to select more than one. The text cursor should move between them when the arrow keys are pressed (not between each letter inside of them) and pressing shift-arrow should select one token at a time, the same way it selects subsequent letters.
It seems like, from my research, there isn't currently a way to do this with HTML and CSS only. user-select
in CSS lets you select all the text within an element at once, but not the element itself. I'd like to be able to use something like ::selection.token { border: 1px solid blue }
to change the appearance of the inline-block element itself when it is selected.
This kind of functionality exists in native applications (functions in Apple Numbers, email addresses in Microsoft Outlook or Apple Mail...) but I don't know if I've ever seen it in a web application.
Has anyone solved this problem before, or done something similar?
EDIT: Since writing this, I've discovered a few jQuery/AngularJS plugins that get close to the functionality I'm looking for. Tokchi is the best one I've come across. (No online demo, unfortunately, so you'll have to download the plugin to check out the demo.) However, even this plugin doesn't have the kind of selection behavior I'm looking to create; selecting a token selects all the text within it, not the token itself.