对 NSTextView 的更改未到达屏幕

发布于 2024-10-03 01:15:23 字数 372 浏览 1 评论 0原文

我有一个 NSTextView,由我自己组装的文本系统支持,按照 Cocoa 文档中文本系统概述中的“手动组装文本系统”部分的内容。它成功地将 NSTextStorage 的内容显示在屏幕上。

但当我输入时,似乎什么也没有发生——屏幕上的文本没有改变。如果我选择文本,则选择的形状表明文本已更改。如果我将文本复制并粘贴到 TextEdit 中,我什至可以看到我的编辑。如果我输入足够多的内容,我可以让它抛出异常:

NSRunStorage, _NSBlockNumberForIndex(): index (5897) beyond array bounds (5881)

天哪,这看起来像是我可以花一天的大部分时间进行调试的事情。这是怎么回事?

I have an NSTextView backed by a text system I put together myself, along the lines of the "Assembling the Text System by Hand" section in the Text System Overview in the Cocoa documentation. It successfully displays the contents of the NSTextStorage on the screen.

But when I type into it, nothing seems to happen—the text on screen doesn't change. If I select the text, the shape of the selection suggests that the text has changed. If I copy and paste the text into TextEdit, I can even see my edits. And if I type enough, I can get it to throw an exception:

NSRunStorage, _NSBlockNumberForIndex(): index (5897) beyond array bounds (5881)

Golly, this looks like the kind of thing I could spend the better part of a day debugging. What's going on here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

吹泡泡o 2024-10-10 01:15:23

确保您将 NSTextStorage 连接到 NSLayoutManager,如下所示:

[textStorage addLayoutManager:layoutManager];

而不是这样:

[layoutManager setTextStorage:textStorage];   //BAD

-[NSLayoutManager setTextStorage:] 上的文档表示永远不应该直接调用它,而只能覆盖它。显然就是这个原因。希望我为您节省了数小时的徒劳工作!

Make sure you connected the NSTextStorage to the NSLayoutManager like this:

[textStorage addLayoutManager:layoutManager];

Instead of like this:

[layoutManager setTextStorage:textStorage];   //BAD

The documentation on -[NSLayoutManager setTextStorage:] says that it should never be called directly, only overridden. Apparently this is the reason. Hopefully I saved you hours and hours of fruitless work!

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