Skip to content
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

Copy and paste cells with system clipboard #1286

Merged
merged 2 commits into from
Apr 4, 2016

Conversation

takluyver
Copy link
Member

This allows cells to be copied and pasted between notebook tabs using (Ctrl/Cmd + C/V), and even between different browsers (on Firefox and Chrome; IE certainly won't work, and from the info on caniuse.com, I doubt Safari will).

I'm not up to speed with our JS conventions, so I'm sure this breaks them in half a dozen ways (I'm a new contributor simulator ;-). But it does work, at least for me.

Limitations:

  1. We're storing JSON data in an HTML mime type in the clipboard. Firefox does not accept application/json data on the clipboard. So I wrap JSON data in <pre class="jupyter-nb-cells-json"></pre> and pretend it's HTML. The code receiving it looks for those tags and gets the JSON data from between them. Not elegant, but it works.
  2. Firefox only fires the paste event if a text input has the focus. There are solutions out there to re-focus an invisible text input after each user action, but I suspect that would mess with our keyboard handling mechanism, so I didn't try it. Instead, as a compromise, pressing Ctrl-V focuses an invisible text input widget and tells you to press it again:

screenshot from 2016-03-30 16-13-43

On Chrome, we can get a paste event without that, so the dialog is not used.

  1. No cut. It should be an easy extension once we're happy with this code, as it's copy+delete.

@juhasch
Copy link
Contributor

juhasch commented Mar 31, 2016

Nice, I never got the copy&paste operation to work with anything else than Chrome in my extension.
It would be nice if you would put a json and plain text version of the cells into the clipboard.
I found that helpful.

@minrk minrk added this to the 5.0 milestone Mar 31, 2016
@takluyver
Copy link
Member Author

Thanks @juhasch - apologies for not basing it on your extension. I didn't think to look for an existing extension, and I was told about it after I'd already got copy & paste working on Chrome.

As you suggested, I've added storing the JSON data with the correct mime type, and storing plain text of just the cell sources so you can paste into a text editor.

@juhasch
Copy link
Contributor

juhasch commented Apr 1, 2016

No problem. I am happy to see this functionality going into the notebook itself.

@Carreau Carreau merged commit eb01a6e into jupyter:master Apr 4, 2016
@Carreau
Copy link
Member

Carreau commented Apr 4, 2016

Thanks All !

@ellisonbg
Copy link
Contributor

Ahh, darn, I wanted to discuss this in the context of integration with
JupyterLab before it got merged.

On Mon, Apr 4, 2016 at 11:25 AM, Matthias Bussonnier <
[email protected]> wrote:

Thanks All !


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#1286 (comment)

Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
[email protected] and [email protected]

@ellisonbg
Copy link
Contributor

I am strong +1 on the feature, but want to make sure users can cut/copy/paste between JupyterLab and the main notebook.

@sccolbert @blink1073 @jasongrout

The main question is if the data being put into the system clipboard is really the best format.

@blink1073
Copy link
Contributor

This seems like a good approach to me.

@sccolbert
Copy link
Contributor

<deleted comment about IE not working> (I should have read the first post).

@Carreau
Copy link
Member

Carreau commented Apr 4, 2016

(I should have read the first post).

Great. Anyway, I guess we can assume people will copy and past between same version of notebook/jupyterlab, so we can update the internal representation if needed without breaking anything.

@ellisonbg
Copy link
Contributor

Should we be including the nbformat string so frontends can reason about
that?

On Mon, Apr 4, 2016 at 1:02 PM, Matthias Bussonnier <
[email protected]> wrote:

(I should have read the first post).

Great. Anyway, I guess we can assume people will copy and past between
same version of notebook/jupyterlab, so we can update the internal
representation if needed without breaking anything.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#1286 (comment)

Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
[email protected] and [email protected]

@sccolbert
Copy link
Contributor

Yeah. I think we should have some discussion on standardizing what the payload should be and for which mimetypes, so that frontends can reason about payloads effectively.

@ellisonbg
Copy link
Contributor

Here is an issue for tracking the clipboard format.

#1321

@booox
Copy link

booox commented May 10, 2016

@takluyver I am a newbie of jupyter and Python. I want to know how to let the nice 'copy/paste' work?

I run the jupyter/notebook, in a running docker container.
The docker image is 'jupyter/notebook', and the run command is:
$ docker run --rm -it -p 8888:8888 -v "$(pwd):/notebooks" jupyter/notebook

I have done the bellow command from Terminal of the notebook.

# python -m pip install -U jupyter

# jupyter --version

4.1.0

@takluyver
Copy link
Member Author

Hi @booox : this work to use the system clipboard is in master (the development version), but not yet in a stable release. If you want to try the development version, follow the instructions here.

With the released version, you can copy and paste cells within a notebook (use shortcuts x, c and v in command mode), but not between notebooks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants