Autocomplete in Cocoa Applications

Thursday, May 26th, 2005 @ 10:14 pm | Mac

The Unofficial Apple Weblog:

If you are in a Cocoa application and typing along, but you just don’t feel like typing the rest of the word you are in the middle of just hit the ‘Esc’ key. A menu with a bunch of different possible completions for the word you started are offered up to you in a nice, scrollable interface. Simply click on the one you want to go with and let the OS do the typing.

This is pretty slick — I know autocomplete was available in Xcode and Script Editor back in Panther, but finding it available system-wide (or, at least Cocoa-wide) is a pleasant surprise.

I’ve played with this for a few minutes and it seems a little smarter than just displaying a list of autocompletion options from the dictionary. If a valid autocompletion option for the selected word already exists in your document, that word appears to jump to the top of the list. The autocompletion option doesn’t even need to appear in the system dictionary — I opened up some source code in TextEdit and I could autocomplete method names.

Furthermore, it appears that if only a single autocompletion option exists, that option is automatically selected. For instance, I hit the ‘Esc’ key after typing “NSA” and “NSAppleEventDescriptor” appeared.

Autocompletion seems to be case sensitive, at least for words that don’t appear in the dictionary.

I’m working under the assumption that this feature is implemented for NSTextView fields. Hopefully, this is something that Carbon applications like BBEdit can add support for over time.

Update: I’ve hit one limitation of the autocomplete system built into Tiger (and probably Panther, as well) — it’s not multi-document aware. This is sort of a downer for coding, since I usually keep my header files and source files open at the same time and I like to use autocompletion was I’m writing method implementations after switching over from writing the declarations in the header files.

So, here’s at least one place where the combination of BBEdit and BBAutoComplete has an advantage over the system’s built-in implementation.

One Response to “Autocomplete in Cocoa Applications”

  1. Tim Buchheim Says:

    It’s been system-wide since Panther. (but you had to use F5 or option-escape … the plain escape shortcut is new.)

    and yes, it is part of NSTextView. See the description of -[NSTextView complete:] in the documentation.