• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Autocomplete word as you are typing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Autocomplete word as you are typing (From: Chris Schmitt <email@hidden>)

  • Prev by Date: Re: Trouble loading bundles at runtime
  • Next by Date: Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
  • Previous by thread: Autocomplete word as you are typing
  • Next by thread: Re: Autocomplete word as you are typing
  • Index(es):
    • Date
    • Thread