The behavior of an NSTextStorage object is best illustrated by following the messages you send to change its text.There are three stages to editing a text storage object programmatically:
The first stage is to send it a beginEditing
message to announce a group of changes.
In the second stage, you send it some editing messages, such as deleteCharactersInRange:
and addAttributes:range:
, to effect the changes in characters or attributes. Each time you send such a message, the text storage object invokes edited:range:changeInLength:
to track the range of its characters affected since it received the beginEditing
message.
For the third stage, when you’re done changing the text storage object, you send it the endEditing
message. This causes it to invoke its own processEditing
method, fixing attributes within the recorded range of changed characters. (See Text Attributes for information about attribute fixing.)
After fixing its attributes, the text storage object sends a message to each associated layout manager indicating the range in the text storage object that has changed, along with the nature of those changes. The layout managers in turn use this information to recalculate their glyph locations and redisplay if necessary. NSTextStorage also keeps a delegate and sends it messages before and after processing edits.
© 1997, 2005 Apple Computer, Inc. All Rights Reserved. (Last updated: 2005-08-11)