• 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
Re: Adding carriage-return behavior to NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding carriage-return behavior to NSTextView


  • Subject: Re: Adding carriage-return behavior to NSTextView
  • From: Max Horn <email@hidden>
  • Date: Wed, 26 Dec 2001 13:40:32 +0100

At 20:57 Uhr -0800 25.12.2001, Esteban wrote:
[...]
More or less that's what I'm using for an application I'm writing. Anyways, maybe someone has a much neater and perhaps better example :)

You can do it without subclassing and all the work (yes! cocoa rules :), and instead add something like this to the delegate of the textview:

- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector
{
if (aSelector == @selector(insertNewline:))
{
// Fetch the current event
NSEvent *event = [NSApp currentEvent];
if ([event type] == NSKeyDown)
{
// Check whether the enter key was pressed
switch ([[event characters] characterAtIndex:0])
{
case NSEnterCharacter:
// Do what you like here;
return YES;
// Add more cases here, possible checking the modifier keys, too
}
}
}
return NO;
}



If you notice in the KeyDownTextView.m's keyDown: method, the KeyDownTextView is its own delegate, you can in code set the delegate to something else and write your own optionreturnHit, optionenterHit, returnHit, enterHit.

You can of course get the same by sending those messages above in the corresponding cases.



Max
--
-----------------------------------------------
Max Horn
Software Developer

email: <mailto:email@hidden>
phone: (+49) 6151-494890


References: 
 >Re: Adding carriage-return behavior to NSTextView (From: Esteban <email@hidden>)

  • Prev by Date: multiple targets/selectors
  • Next by Date: Re: multiple targets/selectors
  • Previous by thread: Re: Adding carriage-return behavior to NSTextView
  • Next by thread: Lists as newsgroups (or: give chuq more work!)
  • Index(es):
    • Date
    • Thread