Username Auto-complete in Halfwit
A couple of nights ago I finally started working on username auto-complete in Halfwit. What’s username auto-complete? That’s the feature whereby you type an “@” sign, and then as you type extra characters, Halfwit looks up your text in the list of recently-seen users and fills in the name for you. Here’s a screen cap:
So in this screenshot I’ve typed “@m” and Halfwit has filled in the first matching name – my own. I then typed “o” and it’s picked the next match – MossyBlog (you can pay me later for the free linkage, MossyBlog).
For the technically minded, here’s how it works.
First, I keep a static List<String> of the 1000 most recently seen usernames. I figured 1000 usernames “ought to be enough for anybody”, but I can make that number larger if the need arises.
Next, I’ve defined an attached property that I can apply to any TextBox. It hooks the KeyUp event of the TextBox and does some simple string manipulation to find a matching name.
The cool part is that this lookup can be based on either the text after an “@” sign, or just the whole text. We need that because there’s another TextBox in Halfwit where you can simply type a username without the “@” prefix. The auto-complete works there, too.
I won’t include the code here – you can grab the whole thing from CodePlex. Check out the “UsernameLookup.cs” file for the attached property class.
Comments
# mabster
7/05/2010 3:11 PM
Note - the code's not committed to CodePlex just yet. Will be in about three hours from now. Patience, young Padawan.