How to observe changes to an NSTextStorage
-
28-02-2021 - |
سؤال
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.
المحلول
You could just write your own subclass of NSLayoutManager and add it to your NSTextSTorage using addLayoutManager:
.
نصائح أخرى
You could also use KVO to observe the characters property of your NSTextStorage object (or any other property of it) and you get exactly what is changed in
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
Use NSTextStorage's getter methods editedRange and changeInLength.
لا تنتمي إلى StackOverflow