• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
-insertNewline: and -insertLineBreak:, using the shift key modifier
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

-insertNewline: and -insertLineBreak:, using the shift key modifier


  • Subject: -insertNewline: and -insertLineBreak:, using the shift key modifier
  • From: Keith Blount <email@hidden>
  • Date: Wed, 11 Jun 2008 13:10:21 -0700 (PDT)

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@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: -insertNewline: and -insertLineBreak:, using the shift key modifier
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: Loading a nib
  • Next by Date: NSTask(syslog)->NSPipe->NSFileHandle->readInBackgroundAndNotify buffers
  • Previous by thread: Re: Bound NSTreeNode - Inserting Children
  • Next by thread: Re: -insertNewline: and -insertLineBreak:, using the shift key modifier
  • Index(es):
    • Date
    • Thread