Cocoa:NSTextStorageDelegate 的 NSLayoutManager 已经过时了?

发布于 2024-09-29 19:25:45 字数 519 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咿呀咿呀哟 2024-10-06 19:25:45

我找到了这个问题的解决方案。如果您注册为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文