NSTextView and tab key navigation
26/04/05 08:50
How to make a NSTextView participates in the keyboard navigation as a normal text field for the tab key but not for the return key ?
Pressing tab should navigate as usual for a text field,
pressing option-tab should insert a tab character in the text,
pressing newline/return - without any modifiers consideration - should insert a newline character in the text,
Pressing tab should navigate as usual for a text field,
pressing option-tab should insert a tab character in the text,
pressing newline/return - without any modifiers consideration - should insert a newline character in the text,
1. sets the NSTextView to be a field edior with [myTextView setFieldEditor:YES];
2. sets the delegate of the NSTextView to an object implementing the following method:
- (BOOL)textView:(NSTextView *)inTextView doCommandBySelector:(SEL)inSelector
{
if (inSelector == @selector(insertTab:)) {
if (([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0) {
[inTextView insertTabIgnoringFieldEditor:self] ;
return YES ;
}
return NO ;
}
if (inSelector == @selector(insertNewline:)) {
[inTextView insertNewlineIgnoringFieldEditor:self] ;
return YES ;
}
return NO ;
}
2. sets the delegate of the NSTextView to an object implementing the following method:
- (BOOL)textView:(NSTextView *)inTextView doCommandBySelector:(SEL)inSelector
{
if (inSelector == @selector(insertTab:)) {
if (([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0) {
[inTextView insertTabIgnoringFieldEditor:self] ;
return YES ;
}
return NO ;
}
if (inSelector == @selector(insertNewline:)) {
[inTextView insertNewlineIgnoringFieldEditor:self] ;
return YES ;
}
return NO ;
}