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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to