0

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.

wagill
  • 57
  • 6

2 Answers2

1

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;
}
  • Thank you for your answer, Daniel. I ended up using your first suggestion, and after doing some more research to figure out how to tell when the app is in full screen mode, I was able to implement the behavior that I want. Thank you again for your help. – wagill Apr 20 '16 at 21:48
0

This is how I implemented the behavior that I wanted:

- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector {

    if (commandSelector == @selector(cancelOperation:)) {

        if (([_window styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask) {

            [textView doCommandBySelector:@selector(toggleFullScreen:)];
        }

        return YES;
    }

    return NO;
}
wagill
  • 57
  • 6