Return key should not end editing in NSTextField
Return key should not end editing in NSTextField
- Subject: Return key should not end editing in NSTextField
- From: Beat Koch <email@hidden>
- Date: Mon, 20 Jan 2003 23:45:59 +0100
I have a multi-line NSTextField. When the user presses Return while
editing that field, a newline character should be entered instead of
the default text-end-editing. I have found a partial solution to do
this by implementing a delegate method for the text field:
- (BOOL) control: (NSControl *) control
textView: (NSTextView *) textView
doCommandBySelector: (SEL) command
{
if (control == myTextField && command == @selector(insertNewline:)) {
[control setStringValue:[NSString stringWithFormat:@"%@\n",
[control stringValue]]];
return YES;
} else {
return NO;
}
}
This works as long as the current insertion point is at the end of the
text but obviously not while it is in the middle. I have tried to send
[control insertNewlineIgnoringFieldEditor:self] but NSTextField does
not implement this method. If I send [control insertText:@"\n"] I just
get a beep.
Is there a better way to get the desired behavior? After having read a
lot of related messages in this list, it seems that subclassing
NSTextField should be avoided. Using an NSTextView is not an option in
this particular case because I have a special NSFormatter attached to
the text field (unless I missed something and I can attach a formatter
to an NSTextView).
Beat
-----
Beat Koch Informatik, CH-3052 Zollikofen, Switzerland
Phone: +41 (31) 914 23 51
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.