不知道如何使用 NSTextView 解决这个问题,但我找到了一个使用 WebView + HTML5 + canvas + javascript 的解决方案
Names are created as canvas objects and text is just normal text in html:
When text is selected, it looks like this:
And after copy+paste you get only conversation as result:
I used canvas because using "-webkit-user-select: none;" in div, text will be copied if you select text around that div. And javascript is needed to create new canvas dynamically.
var canvas = document.createElement("canvas");
canvas.width = 400;
canvas.height = 20;
canvas.setAttribute("style", "-webkit-user-select: none;");
var context=canvas.getContext("2d");
context.font="15px Arial";
context.fillText(text,0,20);
Calling javascript function from objective-c:
[_webView stringByEvaluatingJavaScriptFromString:@"myFunction()"];
So this solution is very easy to implement.