My app has NSTextFields for input; I purposely do not use NSNumberFormatter in order to do special handling of input. The app implements "full screen" mode. When the app is in full screen, and the focus is in a text field, and I press the ESC key to resume windowed mode, instead I get a pop-up with spelling suggestions/completions. I don't want either of these behaviors when the ESC key is pressed: A completions pop-up, nor not being able to exit full screen mode. Any suggestions? Thanks.
You need to setup a NSTextFieldDelegate
to handle that command, and set the delegate on the textfield. Here's an example:
@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSTextField *textField;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
self.textField.delegate = self;
}
- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector {
if (commandSelector == @selector(cancelOperation:)) {
NSLog(@"handleCancel");
return YES;
}
return NO;
}
```
If you just wanted to eliminate spelling suggestions, you could override the following method, but the above does both.
- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index {
return nil;
}