Re: Autocomplete word as you are typing
Re: Autocomplete word as you are typing
- Subject: Re: Autocomplete word as you are typing
- From: Joshua Emmons <email@hidden>
- Date: Wed, 6 Feb 2008 16:48:44 -0600
I know there is the
"textView:completions:forPartialWordRange:indexOfSelectedItem:"
delegate method, but I want something that will happen as the person
types without hitting the escape key.
I did something similar in the following way:
First I subclassed an NSTextField and overrode its keyUp method like so:
-(void)keyUp:(NSEvent *)event{
int keyCode = [event.characters characterAtIndex:0];
if (keyCode != 13 && keyCode != 9 && keyCode != 127 && keyCode !
= NSLeftArrowFunctionKey && keyCode != NSRightArrowFunctionKey) {
[self.currentEditor complete:self];
}
[super keyUp:event];
}
The if block checks to make sure that the key pressed is not
backspace, delete, an arrow key, or any of that stuff that you really
don't want completion to happen after, then calls complete: on its
field editor (this is, as far as I know, equivalent to pressing ESC).
If you want to complete using the default dictionary words, that
should be all you have to do. If, however, you want to suggest your
own words, you should also override
textView:completions:forPartialWordRange:indexOfSelectedItem: to
return something useful. See:
o http://tinyurl.com/3xrdhf
o http://tinyurl.com/3xrdhf
o http://tinyurl.com/3xrdhf
Cheers,
-Joshua Emmons
_______________________________________________
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