-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
"Programmatic" copy to clipboard don't work in Jupyter 5 #2975
Comments
A solution (that I haven't really thought through) is to re-implement a little of what clipboard.js does, something like -
( There is also the question of handling the plain text + json + html, also how it could affect #1321, etc) |
My understanding is that we can only interact with the clipboard by capturing clipboard events, so capturing keyboard shortcuts like Ctrl+C won't work. The MDN docs for document.execCommand say that it's only available in 'design mode', which I know ~nothing about. |
@takluyver I'll try to make a WIP PR ? |
OK |
It is possible to fire off a copy event by creating a temporary invisible textarea, set its value to what you want to copy and focussing it. Then, when the user hits Another instance of this issue popped up recently - twosigma/beakerx#6227 Do you think we can have an "escape hatch" for the notebook's copy (It is a really good feature btw) feature? Similar to how MathJax provides a |
@takluyver @gnestor Please let me know what you think of the last part of my previous comment -
|
If you can see how to implement it, PRs are welcome! I'm a bit hazy on what we can do with the clipboard - I thought we could only respond to clipboard events generated by the browser, but it sounds like |
We have a function for this in @jupyterlab/apputils. |
@takluyver Thanks, I'll give it a shot. But do you see any issue with adding a workaround - something like Madhu94@083f2c8 ? |
If that works, it looks fine. I don't know how |
Because of #1286, any extension that relies on
document.execCommand('copy')
for copying to clipboard don't work, as the notebook captures all copy events triggered.For instance, if a notebook extension used clipboard.js - an invisible textarea is created whose value is set to whatever is supposed to go on the clipboard. In that case window.getSelection().isCollapsed is set to True and the contents of the cell (not the value of the invisible textarea) is stored in the system clipboard.
In this case,
Ctrl+C
would never be pressed and it is surprising for the extension users to click a button on the toolbar or access a menu-item and find that the current cell's contents are copied over.A workaround might be to disable
Jupyter.keyboard_manager
and re-enable it once the extension's work is done.Do you think the notebook can somehow try to detect explicit requests to copy (when the user hits
Ctrl+C
) as opposed to capturing all copy events that are fired ?Thanks!
The text was updated successfully, but these errors were encountered: