• 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: setting tab stops in a document
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setting tab stops in a document


  • Subject: Re: setting tab stops in a document
  • From: Boyd Collier <email@hidden>
  • Date: Mon, 7 Jun 2010 15:37:20 -0700

Paul,

You're quite right.  I commented out the call to shouldChangeTextInRange: and my code still does what I want.  Thanks for pointing this out.

I'll have a look at the documentation on methods for bracketing multiple changes to the text (after I get my head around efficiently creating triangular matrices).

Boyd


On Jun 7, 2010, at 9:30 AM, Paul Sanders wrote:

> > /** ADDED CODE **/
> > NSMutableDictionary* typingAttributes = [[myTextView typingAttributes] mutableCopy];
> > [typingAttributes setObject:paraStyle forKey:NSParagraphStyleAttributeName];
> > [myTextView setTypingAttributes:typingAttributes];
> > NSRange rangeOfChange = NSMakeRange(0, [[myTextView string] length]);
> > [myTextView shouldChangeTextInRange:rangeOfChange replacementString:nil];
> > [[myTextView textStorage] setAttributes:typingAttributes range:rangeOfChange];
> > [myTextView didChangeText];
> > [typingAttributes release];
> > // end added code
>
> It's probably harmless but I don't think it's appropriate to call shouldChangeTextInRange: here as this is not a 'user-initiated editing change', see
>
> http://developer.apple.com/mac/library/documentation/cocoa/reference/ApplicationKit/Classes/NSTextView_Class/Reference/Reference.html#//apple_ref/doc/uid/20000373-BBCCCCBE
>
> You should call didChangeText though, so that the appropriate notifications are sent.  didChangeText doesn't get called for you when you modify the NSTextStorage object programmatically.
>
> Just in case you missed it, you might also like to know about the beginEditing and endEditing methods of NSMutableAttributedString (from which NSTextStorage derives).  These can be used to 'bracket' multiple changes to the text and so doing improves efficiency.  This is covered here:
>
> http://developer.apple.com/mac/library/documentation/cocoa/conceptual/TextEditing/Tasks/BatchEditing.html
>
> Again, for what you are doing here this is not really relevant; the code you posted should work just fine.  But if you are making a number of changes at the same time it is worth calling these methods.
>
> Regards,
>
> Paul Sanders.
>

_______________________________________________

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

References: 
 >setting tab stops in a document (From: Boyd Collier <email@hidden>)
 >Re: setting tab stops in a document (From: Ross Carter <email@hidden>)
 >Re: setting tab stops in a document (From: Boyd Collier <email@hidden>)
 >Re: setting tab stops in a document (From: "Paul Sanders" <email@hidden>)

  • Prev by Date: Re: Custom field editor context menu
  • Next by Date: Re: Scrolling Behavior of NSTextView
  • Previous by thread: Re: setting tab stops in a document
  • Next by thread: Re: setting tab stops in a document
  • Index(es):
    • Date
    • Thread