Re: Return and Enter keys in NSTextView
Re: Return and Enter keys in NSTextView
- Subject: Re: Return and Enter keys in NSTextView
- From: Greg Titus <email@hidden>
- Date: Thu, 30 Aug 2001 09:43:12 -0700
On Thursday, August 30, 2001, at 08:33 AM, Douglas Davidson wrote:
This is somewhat similar. You want the textview to act like a field
editor, as above, except that you want return to be bound to
insertNewlineIgnoringFieldEditor:, something that otherwise you would
get with option-return. There may be a way to do this without
subclassing, but I can't think of one right now. You could subclass,
override insertNewline:, and check [NSApp currentEvent] to see if it is
an unmodified return; if it is, call [super
insertNewlineIgnoringFieldEditor:sender], and if not just call [super
insertNewline:sender].
Instead of subclassing, you could be the NSTextView's delegate and
implement -textView:doCommandBySelector: to do essentially the same
thing...
- (BOOL)textView:(NSTextView *)aTextView
doCommandBySelector:(SEL)aSelector;
{
if (aSelector == @selector(insertNewline:) && ([NSApp
currentEvent] ... is an unmodified return ...)) {
[aTextView insertNewlineIgnoringFieldEditor:self];
return YES;
}
return NO;
}
--Greg