• 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
Best way to modify user input into NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Best way to modify user input into NSTextView


  • Subject: Best way to modify user input into NSTextView
  • From: Zac Samuel <email@hidden>
  • Date: Tue, 31 Mar 2009 21:47:26 +1100

Hi,
I'd like to override the behavior of an NSTextView so that when a certain
character is typed, a different character is inserted. For example I'd like
"×" to be inserted when the user types "*".  This can be done really easily
using the shouldChangeTextInRanges:replacementStrings delegate method:

For example:

**
*

- (BOOL)textView:(NSTextView *)textView
shouldChangeTextInRanges:(NSArray*)affectedRanges replacementStrings:(
NSArray *)replacementStrings{

 if ([[replacementStrings objectAtIndex:0] isEqualToString:@"*"]){

[textView insertText:@"×"];

return NO;

}

return YES;

}


However I don't feel like this is the way to go. It seems to be that these
delegate methods should only be for preventing user input in certain
circumstances, not for actually inserting or adding text. For a start this
approach seems to disrupt the way NSTextView handles undos, and if an
NSTextAttachment were to be inserted instead of plain text, the layout of
the view will not update.

Can anyone suggest the "correct" way of doing such modify user input into
NSTextViews?

Much obliged,

-Zac
**

***
_______________________________________________

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

  • Prev by Date: Need help for user interface in COCOA + Objective C
  • Next by Date: How to know when a UISwitch is being touched
  • Previous by thread: Re: Need help for user interface in COCOA + Objective C
  • Next by thread: Re: Best way to modify user input into NSTextView
  • Index(es):
    • Date
    • Thread