Skip navigation.
 
mlRe: Autocomplete word as you are typing
FROM : Joshua Emmons
DATE : Wed Feb 06 23:48:44 2008

> 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

Related mailsAuthorDate
mlAutocomplete word as you are typing Chris Schmitt Feb 6, 22:50
mlRe: Autocomplete word as you are typing Stéphane Sudre Feb 6, 23:43
mlRe: Autocomplete word as you are typing Joshua Emmons Feb 6, 23:48
mlRe: Autocomplete word as you are typing ? ?? Feb 7, 00:46
mlRe: Autocomplete word as you are typing ? ?? Feb 7, 00:51