22

Whenever I copy code from a Stack Overflow post and try to paste it into Visual Studio or Notepad, all the carriage returns are lost and I have to go through and fix everything. Is there a proper way to do this so the carriage returns are maintained?

Update

This bug is with Internet Explorer (7 and 8). It seems to work fine in Firefox and Chrome.

  • 4
    sux, there should indeed be a "Copy code" link above each snippet like in all normal dev sites. – Shimmy Aug 25 '09 at 2:10
  • 2
    Apparently this is a regression, as this happens again. I remember it being fixed for some time previously but currently it is broken again. So how do we label this? status-to-be-fixed-again? – Joey Nov 25 '10 at 14:09
  • @Joey - I added "vote-to-reopen" I hope this is the right way to do it, also it seems someone reported on the regression, maybe voting up on it will also help meta.stackexchange.com/questions/83992/… – Eran Medan Mar 27 '11 at 2:10
  • Doesn't format properly with IE9 either – StuTheDog Mar 27 '11 at 22:04
7

See here:

Why doesn't IE7 copy <pre><code> blocks to the clipboard correctly?

Also I believe this is on the Google code prettify guys' radar now, as I saw multiple tickets on it. It is easier for them to fix!


Update: the latest version of Prettify was deployed a few days ago; I verified that I can copy and paste from Internet Explorer in the sample post demonstrating the original issue fine. Kudos to Mike Samuel at Google for getting this fix in!

|improve this answer|||||
2

I agree that this is annoying. My workaround is to click "edit" and copy the code out of the text editor there, but this doesn't work so well if you're under 2k rep.

Note: I'm on IE7 most of the time. I don't know if this is a problem on other browsers.

|improve this answer|||||
2

The work around is copying it to Microsoft Word, then copying it to Notepad. Yes, it is Internet Explorer.

|improve this answer|||||
  • This works with IE8 and Word 2007 on XP. – tharen Feb 7 '12 at 22:17
1

It seems to be back again: Prettified code copied in Internet Explorer pastes without line breaks (I agree)

|improve this answer|||||
0

Verified this in IE8 on Windows7 as well. IE6 on Windows XP SP2 does not appear to be affected.

|improve this answer|||||
0

I have the same problem with IE8. I made a pasting test in C#. If I use the command

string s = System.Windows.Forms.Clipboard.GetText();

s contains no CR and no LF, just spaces (" ") in the positions where the line breaks should be.

With

string s = System.Windows.Forms.Clipboard.GetText(TextDataFormat.Html);

however, I get some HTML code within which code examples from stackoverflow are hardly recognizable. Probably MS-Word decodes this HTML code, but VS and other editors fail to do so.

|improve this answer|||||

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .