I'm working with a NSTextView and have a delegate set for its -textStorage
property. Upon receipt of -textStorageDidProcessEditing:
I need to apply attributes to portions of the text.
My attributes are being applied, but they are always applied to 开发者_StackOverflowthe text before I made the edit, even though I'm invoking NSLayoutManager's methods not from -will...
but did...
.
It's as if the layout manager does not know about the recent glyph insertion/deletion at this point in execution, so I assume NSTextView/NSTextStorage invokes the delegate method then notifies the layout manager to update.
Is there a way I can force the layout manager to update with immediate effect so that I can get this to work?
I'm aware of NSTextStorage
's -addAttribute:value:range:
method(s) and have been using those successfully up to this point, but I've hit a point where I need to now do this via the layout manager instead as part of a refactoring/optimizing exercise.
I found a solution to this issue. If you register as a delegate for both NSTextStorage's -textStorageDidProcessEditing:
and NSLayoutManager's -didInvalidateLayout:
notifications then you can effectively "queue" an operation from the text storage delegate, that will only run once the layout manager delegate receives a notification that it's safe to do so.
精彩评论