Fine-tuning NSTextField auto completion
Fine-tuning NSTextField auto completion
- Subject: Fine-tuning NSTextField auto completion
- From: Nala Gnirut <email@hidden>
- Date: Tue, 04 Oct 2011 15:32:44 +0200
Hi all,
in my project I'm using NSControlTextEditingDelegate to auto complete what's
typed in a NSTextField with search location suggestions retrieved from
Google Maps API. "complete:" message is automatically sent to field editor
by a NSTimer short after user ends typing.
Now I'd like to fine-tune the behavior of auto-completion and have it
working exactly as Google search text field works in Safari:
1) When two or more words (separated by spaces) are typed in NSTextField,
location for NSRange passed in
- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView
completions:(NSArray *)words forPartialWordRange:(NSRange)charRange
indexOfSelectedItem:(NSInteger *)index
starts after the last space typed.
This means that if user types "San Fran" and Google APIs returns "San
Francisco", choosing it from auto-complete list NSTextField value is
replaced with "San San Francisco".
My current workaround consist in rebuilding NSArray containing completion
and returning only part of the actual completions returned by Google API,
depending on charRange.location. This looks crappy (because auto-completion
list now shows only part of the completion string), so I want to have
NSTextField ignore spaces when requesting auto-completion.
2) Choosing an auto completion from list, default NSTextField action is not
sent. At the moment user need to choose an auto completion and then press
enter to trigger search. This happens because in IB I chose to send action
on enter only. This is the expected behavior for user not choosing a
completion, but I want action sent on auto-completion.
Thanks in advance.
_______________________________________________
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