-
Notifications
You must be signed in to change notification settings - Fork 29.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support the ability to copy to clipboard in extensions #217
Comments
Perhaps tangentially related: currently, on Linux, selecting text doesn't copy to the X clipboard. Nor does middle-clicking paste. Would be nice to have. |
I am confused... copy in VSC, paste in xterm seems to work. Am I missing something here? |
Ouch - I'm sorry. I meant to say "for Extensions" - going to edit now. On Fri, Nov 20, 2015 at 6:35 PM, Andrew MacKenzie [email protected]
Raymond Camden, Developer Advocate for MobileFirst at IBM Email : [email protected] |
@cfjedimaster You should use a node module for this, like https://github.com/xavi-/node-copy-paste |
Respectfully I disagree. I think the Editor can do more to enable extension developers to be productive. Accessing the clipboard is - imo - not something I should have to go to Node for. It really should be baked in. |
I agree to the point being able to use the simple copy&paste and those should be accessible via the respective command. Tho being able to modify the clipboard contents is different story and I think it's fair to draw the line there |
@jrieken It's fairly common for editors to provide advanced clipboard features beyond what the system provides, and it makes sense for the feature to exist as an extension, e.g. vscode-multiclip. I'm writing an extension that needs to be able to copy arbitrary text into the clipboard (not just the editor selection), and it would be great if it played nicely with vscode-multiclip or any other extension that provides advanced clipboard features. Requiring that my, and all others' extensions, know about such clipboard-extensions in order to access their exported API (if one is even provided) is unreasonable. Edit: VSCodeVim is another example where an extension extends the clipboard functionality. |
Same with emacs bindings -- e.g. in emacs you can keep typing Is there any reason why the line is drawn at modifying clipboard contents? Extensions can execute arbitrary code, so it's not security... |
The recommendation to use https://github.com/xavi-/node-copy-paste isn't ideal - on my system that doesn't work. I've no idea why, and can't suggest an obvious way to debug it, but it breaks vscodevim for me. As a user of VS Code, and not an node programmer, I can't even really offer a test case they can work with, so I ended up raising a big report on vscodevim, which they may be unable to address as it's a problem in a 3rd party module, and I'm left unable to use vscodevim. IMO, access to the same clipboard data that VSCode uses is a pretty reasonable thing to expect from the extension API. |
This is a huge frustration for VSCodeVim. node-copy-paste isn't a solution; it has a number of issues. So do all the other clipboard libraries. Please consider reopening this so we don't have to redebug the wheel. |
node-copy-paste do not work correctly with non-ASCII characters. see #16261 |
@jrieken Can we revisit this? All I wanted to do is to put a image into the clipboard. I spent 2 hours studying all the options and none of them work. https://github.com/xavi-/node-copy-paste has been abandoned for a year and half and is buggy for many people. Currently the only sane way to do this cross-platform is |
Selfishly, I want image support and html/rtf, so that extensions like polacode can put an image on the clipboard. My scenario is I want to be able to quickly paste code samples into slides and blog posts, I had to write my own tool to work around this: https://github.com/slang25/html-copy-vscode. |
For the vscode-mssql extension it would be super helpful to expose the entire Electron clipboard API instead of partially exposing it or reimplementing it. This will let us give our users the ability to copy/paste sql query results with or without special formatting, and in the future if the image clipboard APIs etc are exposed then it would enable things like “copy as image” |
Hm, rtf and html might be quite easy but images are harder without leaking the electron image type into the API... |
@slang25 @mattlrv how would you provide an image? in what format would you have them and how would you expect use to accept it? data uri? file uri? byte array? |
@jrieken For Polacode it's byte array. |
@octref what format, bitmap? |
Plan is to design this to be like the async clipboard API: https://www.w3.org/TR/clipboard-apis/#async-clipboard-api, https://developer.mozilla.org/en-US/docs/Web/API/Clipboard. Something like this readText():Promise<string>;
writeText():Promise<string>;
read():Promise<Data>;
write(data: Data):Promise<void>; The more generic |
This is done as proposed API. The finalisation will happen next milestone. |
To verify, write an extension that uses this API proposal: https://github.com/Microsoft/vscode/blob/25589f6cc4aa3450450fa0f49979fcf7835f52d4/src/vs/vscode.proposed.d.ts#L42-L50 |
For verifier: I made a sample to illustrate how to use proposed api. Maybe you can use this as a starting point for testing the clipboard API: https://github.com/Microsoft/vscode-extension-samples/tree/ext-docs/proposed-api-sample |
Will extensions ever have the ability to read and write custom clipboard formats? Text is a great start, but I have a situation where a tool is putting xml data on the clipboard with a custom format. I'd like to be able to handle this in an extension and show the xml in vscode. Since its a custom format, there is no data in the 'text' buffer of the clipboard and pasting into notepad (or vscode) for example yields nothing. I have a simple UWP app that achieves what I want; but I'd love to scrap that standalone and run it as a vs code plugin. |
@jrieken I saw that. I could not find readData/writeData in vscode.proposed.d.ts though and in vscode.d.ts I only see the readText/writeText methods. So I was wondering if comment 217 was still the long term plan or if it was only for text data. In any event, is this the right issue to watch for clipboard related api changes going forward? |
Support writing (and maybe reading) the system clipboard.
Why I need it: I want to write an extension that will take the contents of the current editor, modify it (by escaping < and >) and then copy that modified text to the clipboard.
The text was updated successfully, but these errors were encountered: