如何将所有属性内容从 NSTextView 复制到 NSPasteboard
我正在尝试实现从 NSTextView 到剪贴板的自动复制内容,以便将来将其粘贴到编辑器中。 NSTextView 具有纯文本和属性文本和图像。
如果我选择全部并按 CMD+C 进行复制并粘贴到某个丰富的编辑器(例如 Mail.app),一切都很好。
我发现这个解决方案可以在 CocoaDev.com 上复制 RTF
但是当我尝试复制时如果我粘贴到编辑器中,我通过此解决方案的内容不会发生任何事情。
如何将带有图像的属性文本从 NSTextView textStorage 复制到 NSPasteboard?
I'm trying to implement auto copy content from NSTextView to clipboard for pasting it in editor in the future. NSTextView has plain and attributed text and images.
If I select all and copy by pressing CMD+C and paste to some rich editor (for example Mail.app) everything is fine.
I found this solution to copy RTF on CocoaDev.com
But when I'm trying to copy my content through this solution is nothing happening if I pasting then in editor.
How to copy attributed text with images from NSTextView textStorage to NSPasteboard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所需要的只是使用 NRTFDPboardType。
All that was needed is to use NSRTFDPboardType.
文本视图的文本存储是 NSTextStorage 的实例,它是 NSMutableAttributedString 的子类。考虑到这一点,请查看 将 NSAttributedString 复制到粘贴板,您将拥有所需的一切前进。
Your text view's text storage is an instance of NSTextStorage, which is a subclass of NSMutableAttributedString. With that in mind, look at Copy NSAttributedString to pasteboard and you'll have everything you need to move forward.