microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.05k stars 29.21k forks source link

Add ability to copy formatted code to clipboard #3518

Closed thomas-taylor closed 7 years ago

thomas-taylor commented 8 years ago

I'd like to request adding the ability to copy selected code to the clipboard with syntax highlighting. This is useful for pasting formatted code into another application (e.g., Word document, e-mail). Regular Visual Studio does this by default (it puts both text and RTF formats on the clipboard). RTF works well for me, but maybe HTML would be okay too, as long as it is 'pastable' (dependency-free).

sushruth commented 8 years ago

:+1:

pcgeek86 commented 8 years ago

We definitely need this. I'd like to copy / paste formatted code into PowerPoint presentations.

harikrishkk commented 8 years ago

Thumbs up!.. Would be awesome if the code can be copy pasted along with the syntax highlighting into word or ppt!.. Such a good IDE, especially with typescript + angular 2 combo , this wud be like gold for me!...Please provide syntax highlighting..

theramiyer commented 8 years ago

Would love this feature! We regularly share code, and it would be much easier to read/understand if there's color coding and indentation.

nicsu commented 8 years ago

👍

Tyriar commented 8 years ago

You should be able to write an extension to do this, you would need to include a syntax highlighter in the extension though. I'm not sure we would want to integrate something like this into the core editor (concerned about feature bloat).

andybrodie commented 8 years ago

I would really like this feature. I was quite surprised that this wasn't already supported when I tried it (I'm a Visual Studio user!). If an extension had to do its own syntax highlighting I think that wouldn't be a great user experience, as I find how VSCode highlights absolutely fine and wouldn't want to have to manage a separate highlighter configuration.

Are you concerned about feature bloat from an end-user perspective or from the codebase itself? I wouldn't comment on the latter, but from an end-user perspective, I enjoy the fact that it's seamless on VS. i.e. VS copied the colour information and if I tried to paste in to an app that didn't support colour (e.g. notepad) then it just disappeared and the app behaved as if I was pasting plain text. In apps like PowerPoint (where I regularly copy and paste code snippets!) I have the source formatting and plain text options available.

skywalkerlw commented 8 years ago

+1

Xarkam commented 8 years ago

:+1:

SirwanAfifi commented 8 years ago

:+1:

crazyquark commented 8 years ago

👍

sushruth commented 8 years ago

Is there anything that is blocking this, or is it not a desired feature ?

ryansmccoy commented 8 years ago

Dear GitHub Gods,

Please add this feature.

Sincerely, Ryan

steveluc commented 8 years ago

Would love to see this happen. Great for communicating about code.

atian25 commented 8 years ago

there is a plugin for atom: https://atom.io/packages/copy-as-rtf

and Code highlighting for Keynote presentations

maybe someone can write a plugin to wrap these

atian25 commented 8 years ago

HI, I had just publish a plugin for this:

theramiyer commented 8 years ago

Hey, thanks, Atian! We'll check it out!

johncruise commented 8 years ago

Hello @atian25,

Thanks for the extension but it copies the text and put "literal" RTF signatures/tags (whatever people call them) around it. So when I paste the code, I get something like this:

{\rtf1\ansi\uc0\deff0{\fonttbl{\f0\fmodern\fprq1\fcharset0 Monaco;}}{\colortbl;\red136\green136\blue136;\red186\green33\blue33;\red0\green68\blue221;\red102\green102\blue102;\red64\green128\blue128;\red160\green160\blue0;\red25\green23\blue124;\red0\green128\blue0;\red187\green102\blue136;\red187\green102\blue34;\red136\green0\blue0;\red170\green34\blue255;\red153\green153\blue153;\red0\green160\blue0;\red160\green0\blue0;\red255\green0\blue0;\red128\green0\blue128;\red176\green0\blue64;\red0\green0\blue255;\red187\green187\blue187;\red188\green122\blue0;\red0\green0\blue128;\red125\green144\blue41;\red210\green65\blue58;}\f0 \fs50{\chbrdr\chcfpat16 @}unittest.skipIf(mock is None, {\cf2 "`mock` module not installed!"})\par

... when I am expecting a color coded text similar to below:

@unittest.skipIf(mock is None, ...)

If it helps, I'm pasting it into an blank Outlook email window.

For those who want an interim solution, look at Notepad++'s NppExport plugin (Copy HTML to clipboard)

croppercapture 2

atian25 commented 8 years ago

hey, @johncruise

the gif is truncated, can't see what menu is selected.

the extension is use pygments behind, and it offer HtmlFormatter

so, for now, you can:

but, I don't know whether copy-paste module can copy it to clipboard with correct format (see https://github.com/atian25/vscode-copy-syntax/issues/1)

I don't have window and outlook now, could you please have a try and feed back?

btw, you can report an issue/suggest at https://github.com/atian25/vscode-copy-syntax/issues

atian25 commented 8 years ago

@Tyriar does vscode have any api for extension to set clipboard?

Tyriar commented 8 years ago

@atian25 there is no copy and paste in the API, I think the advice is to pull in a node module which does it for you.

nashwaan commented 7 years ago

@Tyriar This capability should be part of native VS Code experience, not as a plugin. If anyone doesn't like the colors, he can simply select the pasted code and apply a single color to them.

How many 👍 do you need before getting convinced to implement it as part of VS code? ; )

lazywinadmin commented 7 years ago

+1 Definitely need this !!

rebornix commented 7 years ago

We hear your voice and I'm working on it :)

harikrishkk commented 7 years ago

Awesome! awesome! awesome! requesting you to make it something like the "Copy as HTML" in one of the simple editors like Notepad++ , where, whatever be the Theme, the copied one will also copied like the theme!..cant wait to see the same working on VS code. I see a "Copy syntax as" in the plugins for VS Code, but seems nothing close to the one I saw in Notepad++ or Webstorm.

On Thu, Feb 9, 2017 at 6:38 AM, Peng Lyu notifications@github.com wrote:

We hear your voice and I'm working on it :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode/issues/3518#issuecomment-278515230, or mute the thread https://github.com/notifications/unsubscribe-auth/AEyqyLgt2UPK3FFrWYhlL8ovkIj6ylqUks5ramclgaJpZM4HkOob .

rebornix commented 7 years ago

@harikrishkk I enjoyed the moment that what you describe is what I did. We converted the content with theme into HTML with inline CSS then it can be as compatible as possible.

Meligy commented 7 years ago

Can Insiders build users try the early stages of this with some flag or so?

Cheers,

rebornix commented 7 years ago

You should be able to see this Copy with Syntax Highlighting feature from Friday's Insider update. Please let me know if you guys find any problem with it :)

I would close this issue once tomorrow's Insider is out, thank you all for your patience and feedback.

copy-with-syntax-highlighting

AroraMunish commented 7 years ago

Getting the error Command Failed: Python -v untitled

andybrodie commented 7 years ago

Thanks for the update on this and for your hard work on this feature.

Certainly looks like the fundamentals are working, font and colour information is coming across.

I tried with some Go code, pasting in to PowerPoint 2016, but it didn't paste the background correctly, as the text box it created wasn't configured with the right dimensions. TBH I wasn't expecting the background to come across at all.

image

I also compared with VS2015 on some C# code. VS2015 didn't attempt to take across a background and pasted white text from VS2015 as black text in to PowerPoint, taking in to account the background colour change from dark to light. Would it be possible to mimic VS2015's behaviour with this feature as this works perfectly for what I want to achieve.

Meligy commented 7 years ago

I love it as it now!

I tried it in Gmail opened in Chrome, and in Word, both on Mac. The result is super impressive!

I love that it picked the background. I guess for copying to Word if you want a white background temporarily switch to a theme that matches what you want.

It picked everything, except for TypeScript error underlines, which is exactly what I'd expect and want it to do.

Thanks heaps!

thomas-taylor commented 7 years ago

Looks great! Many thanks for adding this feature!

I was surprised when first testing that it includes the background (dark theme in my case). Sometimes I don't want this, such as pasting in a report (e.g., Word document), but it is easy enough to switch themes when I want the light background. So, the implementation is perfect for me.

harikrishkk commented 7 years ago

Can someone tell me the steps to try this out? I updated the visual studio code to latest version, set the editor.copyFormat to true in settings, but trying to copy paste still throws "command.copySyntax" not found error.

On Fri, Feb 17, 2017 at 8:07 PM, thomas-taylor notifications@github.com wrote:

Looks great! Many thanks for adding this feature!

I was surprised when first testing that it includes the background (dark theme in my case). Sometimes I don't want this, such as pasting in a report (e.g., Word document), but it is easy enough to switch themes when I want the light background. So, the implementation is perfect for me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode/issues/3518#issuecomment-280666402, or mute the thread https://github.com/notifications/unsubscribe-auth/AEyqyHqLW7UymzBA1e5D3wPDUfEZyZETks5rdbC6gaJpZM4HkOob .

schallm commented 7 years ago

This works very nice. It basically seems to mirror the VS2013 copy/paste feature where it copies the background and does a full width paste of the background. If memory serves, VS2012 would copy background, but only under the text, so when pasting you would have jagged ends of the line. VS2015 by default copies with a nice theme (not sure if you can change it), but must not use the current theme. I used a dark background, but when copying/pasting it is a white background.

Many comments are coming that we could easily change the theme if we want to have a different look when pasting. Would it be possible to have a setting like editor.copyTheme in settings.json that would do that for us?

Thanks again for the great feature...

On Fri, Feb 17, 2017 at 8:46 AM, Harikrishnan KK notifications@github.com wrote:

Can someone tell me the steps to try this out? I updated the visual studio code to latest version, set the editor.copyFormat to true in settings, but trying to copy paste still throws "command.copySyntax" not found error.

On Fri, Feb 17, 2017 at 8:07 PM, thomas-taylor notifications@github.com wrote:

Looks great! Many thanks for adding this feature!

I was surprised when first testing that it includes the background (dark theme in my case). Sometimes I don't want this, such as pasting in a report (e.g., Word document), but it is easy enough to switch themes when I want the light background. So, the implementation is perfect for me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <https://github.com/Microsoft/vscode/issues/3518#issuecomment-280666402 , or mute the thread https://github.com/notifications/unsubscribe-auth/ AEyqyHqLW7UymzBA1e5D3wPDUfEZyZETks5rdbC6gaJpZM4HkOob

.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode/issues/3518#issuecomment-280668654, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUNn4YVKoWcAI63mtM799igm_9MQ1GKks5rdbKsgaJpZM4HkOob .

rebornix commented 7 years ago

@AroraMunish does that happen when you just press ctrl/cmd+c? It looks like an extension problem to me.

rebornix commented 7 years ago

@andybrodie I'll give Powerpoint a try on Windows, the output HTML is just simple <div>s so I'll see if I make anything wrong with the layout.

Speaking of VS2015, are you saying that you are using Dark theme in VS2015 and when you copy it to Powerpoint, the pasted content has white background and black font color? Does other colorization still work? A screenshot can help me understand :)

rebornix commented 7 years ago

@harikrishkk Just simply Ctrl/Cmd+C without any configuration.

@thomas-taylor @schallm or anyone uses Dark theme, I'm a Dark theme guy as well. At the very beginning, I didn't put the background color from the theme into the output content, but later on I found for most cases the output is ugly or unreadable. I suppose you can imagine that as for Dark theme, the font color are always light. Light font above white background is terrible most of the time. The dark theme you are using makes sure that the background color and foreground color has good contrast so I choose to ship bkg color to the clipboard.

I can see reasons that why customizing the pasted content style is useful as sometimes you can't easily modify the styles in the target application. Look forward to more users feedback on this once we ship it to stable.

schallm commented 7 years ago

Here is a screenshot of VS2015 (dark theme) with code selected, copied to clipboard, pasted to Outlook... I don't know if they use a different theme when copying, but it works great. I get syntax highlighted code that looks great, but without the dark background...

screenshot

thomas-taylor commented 7 years ago

@harikrishkk - You say you have latest, but just to be sure you know, today this is only in the insider build: https://code.visualstudio.com/insiders

@rebornix - I think the way it matches the theme exactly (including background) is perfect. Regular VS 2015 appears to switch the entire theme (for example text that is white in VS 2015 dark theme is pasted as black text in Word/Outlook). This works fine too (for my needs), but I like your implementation in VS Code better. That said, I also like the suggestion from @schallm to have a setting to choose the theme that you want to use for this cut/paste feature.

harikrishkk commented 7 years ago

Superb! I just installed the one with the insiders link! .what i previously downloaded was the normal one from the vs code site... And i tried copy pasting a sample to word doc! sweet!... A simple crtl+ c, and paste it!.... @thomas taylor, thanks a lot!... [image: Inline image 1]

On Sat, Feb 18, 2017 at 1:24 AM, Thomas Taylor notifications@github.com wrote:

@harikrishkk https://github.com/harikrishkk - You say you have latest, but just to be sure you know, today this is only in the insider build: https://code.visualstudio.com/insiders

@rebornix https://github.com/rebornix - I think the way it matches the theme exactly (including background) is perfect. Regular VS 2015 appears to switch the entire theme (for example text that is white in VS 2015 dark theme is pasted as black text in Word/Outlook). This works fine too (for my needs), but I like your implementation in VS Code better. That said, I also like the suggestion from @schallm https://github.com/schallm to have a setting to choose the theme that you want to use for this cut/paste feature.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode/issues/3518#issuecomment-280750131, or mute the thread https://github.com/notifications/unsubscribe-auth/AEyqyJZ3Hcy35ak_0ysS4HCMfSG-YqPPks5rdfr6gaJpZM4HkOob .

AroraMunish commented 7 years ago

When I try to copy using right click | Copy Syntax, I get the error "Command failed: python -V". Do I need to pre-install anything?

harikrishkk commented 7 years ago

@munish, https://code.visualstudio.com/insiders try downloading the installer from here and see if its working..i had the same issue when i was just trying to take the latest of the VS code from the usual site. After installing this build ( a green one ), it did work for me

On Sun, Feb 19, 2017 at 2:41 PM, Munish Arora notifications@github.com wrote:

When I try to copy using right click | Copy Syntax, I get the error "Command failed: python -V". Do I need to pre-install anything?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode/issues/3518#issuecomment-280906121, or mute the thread https://github.com/notifications/unsubscribe-auth/AEyqyF0YSxaBQIl30R7qz1lEK1p7yKzoks5reAdYgaJpZM4HkOob .

AroraMunish commented 7 years ago

Thanks Harikrishnan .. it worked..

MateenKadwaikar commented 7 years ago

Not working with Powerpoint. I have to copy it in Word first then I have copy from word and paste in Powerpoint

rebornix commented 7 years ago

@MateenKadwaikar is there anyway in Powerpoint that can trigger a force copy with formatting? In Outlook on macOS, I have to do that always as the default paste is just pasting plain text.

Meligy commented 7 years ago

@MateenKadwaikar , +1 to @rebornix. PowerPoint has a default text based paste. From Edit menu though you can choose "Paste Special...", which will give HTML and RTF options. I have found the VS Code HTML copy to work with both.

harikrishkk commented 7 years ago

Is anyone facing issues while copy pasting? I get the code but indentations is all wrong and has to put tab or space every single time. A couple of updates before, it wasnt the case i guess.

On Wed, Feb 22, 2017 at 3:11 AM, Meligy, GuruStop.NET < notifications@github.com> wrote:

@MateenKadwaikar https://github.com/MateenKadwaikar , +1 to @rebornix https://github.com/rebornix. PowerPoint has a default text based paste. From Edit menu though you can choose "Paste Special...", which will give HTML and RTF options. I have found the VS Code HTML copy to work with both.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode/issues/3518#issuecomment-281490195, or mute the thread https://github.com/notifications/unsubscribe-auth/AEyqyGFDg0LecvhvR61GG82TRpPG2JVhks5re1oWgaJpZM4HkOob .

dalyIsaac commented 7 years ago

+1 It doesn't work with OneNote 2016 either

rebornix commented 7 years ago

@dalyIsaac do you mind sharing what platform and version you are using and a gif can help me understand what's going on, thanks!

atian25 commented 7 years ago

Guess:

untitled