My own solution was actually very simple: just add the search bar to the list of suggestions for autocomplete.
This is done in the NSSearchField control:textView:completions:forPartialWordRange:indexOfSelectedItem: delegate method::
... partialString = [[textView string] substringWithRange:charRange]; ... matches = [NSMutableArray array]; // find any match in our keyword array against what was typed - for (i=0; i< count; i++) { string = [keywords objectAtIndex:i]; if ([string rangeOfString:partialString options: NSCaseInsensitiveSearch | NSForcedOrderingSearch range:NSMakeRange (0, [string length])] .location != NSNotFound) { [matches addObject:string]; } } [matches sortUsingSelector:@selector(compare:)]; // Make sure we insert the already entered string, even if it does not // match with any of the retrieved keywords. This will enter this string // in the search field, as we intended, and it will not be overwritten // with any match. [matches insertObject:partialString atIndex: 0]; return matches;
robject
source share