Suppressing autocomplete on space
Suppressing autocomplete on space
- Subject: Suppressing autocomplete on space
- From: Daniel Thorpe <email@hidden>
- Date: Wed, 17 Mar 2010 23:22:29 +0000
Hello everyone,
I know this has briefly been asked before, but the answer provided (just subclass the field editor), isn't really very cocoaish, and the docs are a bit lacking on this, so I'm asking again...
Firstly, the problem...
My app has a few places where the user searches for a person, so I want to provide autocomplete against their Address Book. This is done in a NSSearchField, in a NSTextFieldCell in a NSTableView and in a normal NSTextField. All of these controls have my AppDelegate set as their delegate, and in that class I implement the NSControlTextEditing delegate method:
- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index
to provide my array of names. My implementation of this method currently splits the textView's string up by spaces, and uses the first and last words to search for first and last names. The problem is that when the user types a space, because they are going to type the person's surname, the field autocompletes. This is bad because it might actually be the wrong name and we get a space appended to the completed name. Ideally, I only want to autocomplete on tab.
Now, I've tried implementing all manner of "textWill/DidEndEditing" delegate methods, for both NSControlTextEditing and NSTextViewDelegate protocols, and none of them seem to get called when the user presses space. So, what's going on? How can I get it to only autocomplete on tab, not space?
Also, if the answer really is "just override the field editor", how do I override one class (NSTextFieldCell?) to make it work with the three different input fields? And, lastly, what exactly do I do in the - (void)complete:(id)sender; method? Check the last character, and if it's not space call the super?
I think that's it, any ideas would be most welcome!
Cheers
Dan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden