Hi,
In most text-based apps, you insert a newline by hitting return and a line
break by hitting shift-return. This isn't the default behaviour of NSTextView,
but both -insertNewline: and -insertLineBreak: are available as actions.
However, using interface builder it is impossible to add shift-return as a
keyboard shortcut (it just gets entered as return without the shift modifier),
so the obvious way of implementing this behaviour - having a menu item with
-insertLineBreak: as its action and applying shift-return as its keyboard
shortcut - doesn't work. I tried to get around this by using NSMenuItem's
-setKeyEquivalentModifierMask in my menu delegate (the app delegate). This
changed the shortcut in the menu to shift-return as desired, but using the
shortcut had no effect - a regular newline was entered.
This leads me to believe that shift-return is blocked somehow as a shortcut by
the text system, though I'm not sure how or why.
The only thing I can think of is to override -insertNewline: in my custom text
view to call -insertLineBreak: if the shift key is held down. This works, as
follows:
- (void)insertNewline:(id)sender
{
if([[[selfwindow] currentEvent] modifierFlags] & NSShiftKeyMask)
[selfinsertLineBreak:sender];
else
[super insertNewline:sender];
}
My question is, is there anything wrong with doing it this way? Or is there a
better way of getting the expected line break keyboard shortcut that I am
missing, given that regular routes don't work?
Thanks in advance and all the best,
Keith
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]