Skip navigation.
 
mlNSTextView undo doesn't work for attributes?
FROM : Keith Blount
DATE : Fri Apr 01 22:56:47 2005

Hello,

I am trying to programmatically add some attributed to
a text view like this:

NSAttributedString *attrStr = [[NSAttributedString
alloc] initWithString:string attributes:attribs];
   [self shouldChangeTextInRange:selRange
replacementString:string];
   [[self textStorage] replaceCharactersInRange:selRange
withAttributedString:attrStr];
   [self didChangeText];
   [attrStr release];

attribs is a dictionary that contains indenting in the
NSParagraphStyle attribute. Everything is called here
to set up undo, and yet undo fails to undo the
attributes. So if I use the above code and then hit
undo, the text attributes aren't restored to their
original state - they stay as they were set by
attribs.

Why aren't attributes undone? How can I make it so
that they are?

I tried separating the code into two stages: first I
replaced the string, and then I applied the attributes
using textStorage's addAttributes:range: - this worked
the first time I called undo (attributes were reset),
but if I call redo and undo again, again the
attributes are not reset.

Am I missing something? Surely NSTextView's
shouldChangeTextInRange:replacementString: and
didChangeText: should handle the undo for the whole
attributed string, not just the string part?

Many thanks for any pointers on what I am missing,
Keith

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Related mailsAuthorDate
No related mails found.