Technique on how to format/color NSTextView's string

那年仲夏 提交于 2019-12-05 05:35:20

I think you are right with the approach to set typingAttributes. Reference for -setTypingAttributes: says

However, if you add any user actions that change text attributes, the action should use this method to apply those attributes afterwards. User actions that change attributes should always set the typing attributes because there might not be a subsequent change in selection before the next typing.

That seems to apply in your case.

I don't know if the described behaviour is only correct for WYSIWYG editors like TextEdit. You seem to work on something that is similar in behaviour to an editor with syntax highlighting. There you never really want to change text attributes manually, but rather on structure from a grammar. It probably doesn't fit in that case, and you should reset typingAttributes or set it according to parsing up to there.

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