NSTextView textDidChange/didChangeText not called for bindings

强颜欢笑 提交于 2019-12-05 18:09:14

It would be better to set the font attributes into the NSAttributedString that is bound to the text view's "attributedString". In the textDidChange: delegate method, you can just recreate the NSAttributedString with the correct font attributes.

The NSTextView method didChangeText is not called when a binding updates the text (as opposed to the text view updating the model).

didChangeText is the source of the binding update. If you override it and don't call super, the binding is broken. didChangeText calls the delegate method textDidChange.

Unfortunately, didChangeText is also called rather late in the NSTextView update process - after the layout and storage delegate calls.

I found that the NSTextStorageDelegate method "didProcessEditing" was the best way to catch changes to the bound string. Although you have to be careful what changes you can make back to the textview at this point - some calls crashed.

I answered my own similar question more fully here: NSTextView textDidChange not called through binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!