Re: setting tab stops in a document
Re: setting tab stops in a document
- Subject: Re: setting tab stops in a document
- From: "Paul Sanders" <email@hidden>
- Date: Mon, 7 Jun 2010 17:30:33 +0100
> /** 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