Cocoa:NSTextStorageDelegate 的 NSLayoutManager 已经过时了?
我正在使用 NSTextView 并为其 -textStorage
属性设置了委托。收到 -textStorageDidProcessEditing:
后,我需要将属性应用于文本的部分。
我的属性正在被应用,但它们总是在我进行编辑之前应用于文本,即使我不是从 -will...
调用 NSLayoutManager 的方法,而是做了...
。
就好像布局管理器在执行时不知道最近的字形插入/删除,所以我假设 NSTextView/NSTextStorage 调用委托方法然后通知布局管理器进行更新。
有没有办法可以强制布局管理器立即更新,以便我可以让它工作?
我知道 NSTextStorage
的 -addAttribute:value:range:
方法,并且到目前为止一直在成功使用这些方法,但我遇到了一个问题我现在需要通过布局管理器来完成此操作,而不是作为重构/优化练习的一部分。
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 the 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了这个问题的解决方案。如果您注册为 NSTextStorage 的
-textStorageDidProcessEditing:
和 NSLayoutManager 的-didInvalidateLayout:
通知的委托,那么您可以有效地“排队”来自文本存储委托的操作,这只会一旦布局管理器委托收到可以安全执行此操作的通知,就运行。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.