简体   繁体   中英

How to observe changes to an NSTextStorage

I have an NSTextStorage delegate imlementing textStorageDidProcessEditing: . Unfortunately, the userInfo doesn't contain any details about the changes to the text.

How can I find out what actually changed?

Ideally I'd like to know everything sent to [NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] , but just the edited range would be good enough.

您可以编写自己的NSLayoutManager子类,然后使用addLayoutManager:将其添加到NSTextSTorage中。

您还可以使用KVO观察NSTextStorage对象的characters属性(或它的任何其他属性),然后确切地了解其中的更改

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 

使用NSTextStorage的getter方法editedRange和changeInLength。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM