NSTextStorage is a semi-abstract subclass of NSMutableAttributedString. It implements change management (beginEditing/endEditing), verification of attributes, delegate handling, and layout management notification. The one aspect it does not implement is the actual attributed string storage --- this is left up to the subclassers, which need to override the two NSMutableAttributedString primitives:
/* If there are no outstanding beginEditing calls, this method calls processEditing to cause post-editing stuff to happen. This method has to be called by the primitives after changes are made. The range argument to edited:... is the range in the original string (before the edit).
/* This is called from edited:range:changeInLength: or endEditing. This method sends out NSTextStorageWillProcessEditing, then fixes the attributes, then sends out NSTextStorageDidProcessEditing, and finally notifies the layout managers of change with the textStorage:edited:range:changeInLength:invalidatedRange: method.
*/
- (void)processEditing;
/* These methods return information about the editing status. Especially useful when there are outstanding beginEditing calls or during processEditing... editedRange.location will be NSNotFound if nothing has been edited.
*/
- (unsigned)editedMask;
- (NSRange)editedRange;
- (int)changeInLength;
/* Set/get the delegate
*/
- (void)setDelegate:(id)delegate;
- (id)delegate;
@end
/**** NSTextStorage delegate methods ****/
@interface NSObject (NSTextStorageDelegate)
/* These methods are sent during processEditing:. The receiver can use the callback methods editedMask, editedRange, and changeInLength to see what has changed. Although these methods can change the contents of the text storage, it's best if only the delegate did this.
*/
- (void)textStorageWillProcessEditing:(NSNotification *)notification; /* Delegate can change the characters or attributes */
- (void)textStorageDidProcessEditing:(NSNotification *)notification; /* Delegate can change the attributes */