Skip to content

Copy/paste from SC IDE to Mail loses formatting & tabs (OS X) #657

Closed
totalgee opened this Issue Nov 19, 2012 · 12 comments

4 participants

@totalgee

One disadvantage of the new IDE is that when you copy/paste text from the editor to an email (on OS X, at least), all formatting is lost. The colouring of code isn't so important (though it would be nice -- 3.5.x used to keep it), but the indenting is very important. Right now, when you paste from the IDE to a Mail message, all the code is flush with the leftmost column.

Note: if you paste from SC to TextEdit, there is no formatting, but at least the tabs are kept. So it would be nice if this also worked when pasting into Mail (a workaround is to paste into TextEdit, then copy that new text and paste it into Mail, though that's a bit of a pain).

@jamshark70
  1. This would be better as a mailing list thread.

  2. You can configure the IDE to use spaces, instead of tabs.

  3. IIRC, you can set apple mail to send plain text email, instead of html. That's probably a good idea in general for technical subjects.

@totalgee
@timblechmann

frankly, this sounds more like a bug in apple mail

@totalgee
@timblechmann

neither jakob nor me is using osx, so what worked for you in 3.5, never worked for us. that said, you are more than welcome to have a look at the sources and provide a patch.
iac, please report a bug to apple ...

@jamshark70

There is a difference: SC.app uses a rich text editor while the IDE uses plain text. The issue basically looks like Apple mail doesn't handle plain text pasting very well. I guess it doesn't have to, since the vast majority of Apple mail users are sending baby pictures to grandma rather than code snippets.

Simple test: Write some plain text in TextEdit (make sure to choose the plain text option from whichever menu). Include some tabs. Then copy and paste into an email message. If the tabs disappear, then the issue is not specific to the SC IDE and therefore is unlikely to be fixable within the IDE. If they don't disappear, then the other variable is that the IDE code editor is a qt widget, whereas TextEdit is native cocoa. That might be fixable in the SC codebase, or it could be a qt bug.

I'd suggested this would be better as a list thread because it's not clear that this is, in fact, an IDE bug. If there's doubt, better to start on the mailing list.

@timblechmann

btw, apple mail is known to cause some troubles when pasting: iirc pasting something like SinOsc.ar, as it will convert it to an html link

@jamshark70

Btw, this:

I tried this -- it makes no difference. If I convert everything to spaces, the regular paste still (strangely!) leaves everything left-aligned.

... really sounds like an Apple mail bug. Any reasonable HTML conversion would turn multiple consecutive spaces into non-breaking spaces, or nbsp spc nbsp spc... If Apple mail isn't doing that, then it isn't sc's fault.

@totalgee
@totalgee

(for those who are interested)

Okay, so I've never looked at any Qt code before. I got SC compiling on my Mac for the first time, then tried figuring out where the darn copy/paste code is (turns out there isn't any; it uses the Qt default behaviour from QPlainTextEdit and QTextEdit). The HTML that is copied by SC (for a very simple example) is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><!--StartFragment-->(</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">5.do {</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">   3.postln;</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">}</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">)<!--EndFragment--></p></body></html>

This markup relies on the CSS2 property white-space: pre-wrap, which tells the HTML client not to ignore white space at the start of lines. The HTML above renders properley in Safari and Firefox, of course. So, it looks indeed like this is a bug in Mail (as well as in MS Word, into which I also tried pasting code from SC, just for fun). They maybe aren't CSS2 compliant, or else just do it wrong. I will log an issue with Apple.

Interestingly, if I make an overload for GenericCodeEditor::createMimeDataFromSelection() and have it only put "text/plain" MIME data into the clipboard, of course it pastes properly into Mail -- since the only thing for it to grab then is plain text. Also, as I mentioned earlier, if you paste explicitly as plain text (Cmd-Alt-Shift-V), it also works.

Thanks all for your feedback.
Glen.

P.S. Note that there is no text colour or font information in the HTML copied data from SC. If it were needed or wanted at some point, I suppose we could generate our own HTML code here to copy to the clipboard, with full colour, font, etc.

@jleben
SuperCollider member
jleben commented Nov 19, 2012

P.S. Note that there is no text colour or font information in the HTML copied data from SC. If it were needed or wanted at some point, I suppose we could generate our own HTML code here to copy to the clipboard, with full colour, font, etc.

That's because the syntax highlighting is applied on-the-fly, just before rendering to screen, and does not make part of the document's content. Hence, this is not a bug/feature of HTML generation on copying.

@jleben
SuperCollider member
jleben commented Nov 19, 2012

In any case, I think it would make sense to make the code editor only copy plain text, as that's what code really is.

@timblechmann timblechmann added a commit that referenced this issue Nov 28, 2012
@totalgee totalgee scide: code editor / post window - copy using plain text
fixes #657
(cherry picked from commit 796a8b7)
3a027e1
@sofakid sofakid pushed a commit to sofakid/supercollider that referenced this issue Apr 6, 2015
@totalgee totalgee scide: code editor / post window - copy using plain text
fixes #657
(cherry picked from commit 04cbd76)
658d3ca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.