question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Copy-Paste Formatted Code Doesn't Work Properly On Linux (Works On Windows)

See original GitHub issue
  • VS Code Version: 1.55.2
  • OS Version: Kubuntu 20.04 (Linux)

Steps to Reproduce:

  1. Open VS Code 1.55.2 on Linux
  2. Open a JavaScript (.js) file
  3. Select some code, & Copy
  4. Paste to any ‘Rich Text’ editor (i.e. LibreOffice Writer, AbiWord, WPS Office Writer, or SoftOffice TextMaker).
  5. Observe that there is no indentation in the pasted text

Does this issue occur when all extensions are disabled?: Yes

Full Description:

On Windows, I can copy from VS Code & paste it into i.e. MS Word, and it retains all the correct formatting (both coloring/syntax highlighting & indentation). However, on Linux, there doesn’t seem to be any combination that works: pasting it anywhere else seems to lose either the coloring or the indentation. Here’s a very simple example - source code, as shown in VS Code:

AUYPJ

If I paste it to LibreOffice Writer, WPS Office Writer, SoftOffice TextMaker, or AbiWord, it loses its indentation:

AUYPJ

Conversely, if I paste it to MS Word running in VirtualBox, it keeps its indentation but loses its color:

AUYPJ

Here’s the raw HTML in the clipboard, as shown by CopyQ (a clipboard utility):

<meta http-equiv="content-type" content="text/html; charset=utf-8"><div style="color: #000000;background-color: #ffffff;font-family: 'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback';font-weight: normal;font-size: 12px;line-height: 16px;white-space: pre;"><div><span style="color: #0000ff;">import</span><span style="color: #000000;"> React </span><span style="color: #0000ff;">from</span><span style="color: #000000;"> </span><span style="color: #a31515;">"react"</span><span style="color: #000000;">;</span></div><br><div><span style="color: #0000ff;">function</span><span style="color: #000000;"> withTooltip(Component) {</span></div><div><span style="color: #000000;">    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #0000ff;">class</span><span style="color: #000000;"> WithTooltip </span><span style="color: #0000ff;">extends</span><span style="color: #000000;"> React.Component {</span></div><div><span style="color: #000000;">        state = { showTooltip: </span><span style="color: #0000ff;">false</span><span style="color: #000000;"> };</span></div><div><span style="color: #000000;">        render() { </span></div><div><span style="color: #000000;">            </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> (</span></div><div><span style="color: #000000;">                </span><span style="color: #800000;">&lt;div</span><span style="color: #000000;"> </span><span style="color: #800000;">/&gt;</span></div><div><span style="color: #000000;">            );</span></div><div><span style="color: #000000;">        }</span></div><div><span style="color: #000000;">    };</span></div><div><span style="color: #000000;">}</span></div><br><div><span style="color: #0000ff;">export</span><span style="color: #000000;"> </span><span style="color: #0000ff;">default</span><span style="color: #000000;"> withTooltip;</span></div></div>

If I reboot to Windows & copy-paste from VS Code 1.55.2 to MS Word (or any other Windows richext editor), the formatting comes out properly. The html produced on Windows (also obtained via CopyQ) looks completely different to the html produced by VS Code on Linux. Here’s the html from Windows:

<html>
<body>
<!--StartFragment--><div style="color: #000000;background-color: #ffffff;font-family: Consolas, 'Courier New', monospace;font-weight: normal;font-size: 12px;line-height: 16px;white-space: pre;"><div><span style="color: #0000ff;">import</span><span style="color: #000000;">&#160;React&#160;</span><span style="color: #0000ff;">from</span><span style="color: #000000;">&#160;</span><span style="color: #a31515;">"react"</span><span style="color: #000000;">;</span></div><br><div><span style="color: #0000ff;">function</span><span style="color: #000000;">&#160;withTooltip(Component)&#160;{</span></div><div><span style="color: #000000;">&#160;&#160;&#160;&#160;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&#160;</span><span style="color: #0000ff;">class</span><span style="color: #000000;">&#160;WithTooltip&#160;</span><span style="color: #0000ff;">extends</span><span style="color: #000000;">&#160;React.Component&#160;{</span></div><div><span style="color: #000000;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;state&#160;=&#160;{&#160;showTooltip:&#160;</span><span style="color: #0000ff;">false</span><span style="color: #000000;">&#160;};</span></div><div><span style="color: #000000;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;render()&#160;{&#160;</span></div><div><span style="color: #000000;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&#160;(</span></div><div><span style="color: #000000;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span><span style="color: #800000;">&lt;div</span><span style="color: #000000;">&#160;</span><span style="color: #800000;">/&gt;</span></div><div><span style="color: #000000;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;);</span></div><div><span style="color: #000000;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</span></div><div><span style="color: #000000;">&#160;&#160;&#160;&#160;};</span></div><div><span style="color: #000000;">}</span></div><br><div><span style="color: #0000ff;">export</span><span style="color: #000000;">&#160;</span><span style="color: #0000ff;">default</span><span style="color: #000000;">&#160;withTooltip;</span></div></div><!--EndFragment-->
</body>
</html>

Thus, every time I need to copy formatted code out of VS Code, I find myself having to reboot completely to Windows just to do the copy-paste, as it works fine there, but not on Linux.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:13
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
robross0606commented, Nov 16, 2021

I can report that Teams on Windows also now has this issue.

7reactions
metal450commented, May 16, 2021

I tried pasting code into more than a dozen formatted text editors on Linux and online; I found one where the formatting comes out properly: Google Docs. Everywhere else it doesn’t.

Clearly the problem is VS Code. It’s producing html that the vast, vast majority of text editors don’t understand - so even if there are a few cases that do, it should be producing html that is generally understood, not just understood by a small subset of editors. i.e. VS Code on Windows produces code that is properly formatted 100% of the time, regardless of the editor you paste it to. VS Code on Linux produces code that is apparently recognizable by some small exceptional number of editors, but not by the vast majority of others. Clearly the issue is the HTML it’s producing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VS Code Copy-Paste Formatted Text Not Working On Linux
Edit: As a workaround, I found that I can copy from VS Code, paste to Google Docs, then copy from Google Docs, &...
Read more >
How to Fix When Copy-Paste Isn't Working - Alphr
If you're not able to use keyboard shortcuts for copy-paste, try selecting the file/text using your mouse, then select Copy and Paste from...
Read more >
cannot copy paste WITH formatting - Microsoft Community
Hi, my computer used to copy and paste with formatting just fine. For a few weeks now it cannot copy and paste with...
Read more >
Integrated Terminal in Visual Studio Code
Visual Studio Code has an integrated terminal to enable working in your shell ... Windows: Copy and drop selection if there is a...
Read more >
Copy and Paste Not Working on Windows 10? 7 Best Fixes
This is another solution worth trying. Right-click on the Start button and click Command Prompt (Admin) on the Quick Access menu. Type the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found