jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.58k stars 4.85k forks source link

Standardize system clipboard data format for cut/copy/paste #1321

Open ellisonbg opened 8 years ago

ellisonbg commented 8 years ago

Right now in master, users can cut/copy/paste cells between notebooks in different browser tabs using the system clipboard. Before we release 5.0, we should audit the data format being put in the clipboard to make sure:

  1. It makes sense moving forward.
  2. It can handle notebooks with different versions (should probably include the nbformat # somewhere)
  3. Can work with JupyterLab
TyberiusPrime commented 8 years ago

While this is a nice feature, for me it breaks copying things from the result's section of the cells. Very annoying if you want to copy them to a text editor or such.

takluyver commented 8 years ago

What commit do you have? That sounds very much like an issue that was already fixed in master, so try pulling the latest version if you haven't already.

TyberiusPrime commented 8 years ago

I'm at Wednesdays master. Sorry, pip install does not seem to log the actual commit being used.

takluyver commented 8 years ago

This Wednesday? Can you check that you've rebuilt javascript (python setup.py js) and cleared your browser cache. If you can still reproduce it, please post exact steps, because I thought we had fixed that.

TyberiusPrime commented 8 years ago

Ok, I build a new, clean docker for this. It starts with ubuntu:14.04, and adds apt-fast, and the following packages: build-essential screen vim pigz lbzip2 csh libtool libxml2 liblocal-lib-perl libcurl4-openssl-dev wget liblzo2-dev libzmq-dev libgsl0-dev python3-dev python3-pip npm nodejs-legacy lxc-docker-1.9.1 ca-certificates apparmor fish

It then does an npm install -g configurable-http-proxy.

Followed by pip3 install git+git://github.com/jupyter/jupyterhub.git git+git://github.com/jupyter/notebook.git docker-py ipywidgets

So it has a git commit from within the last three hours.

I have tested with Opera 34.0.2036.25 and Firefox 45.0.2 on Ubuntu 15.11.

To reproduce: Mark text in output of a CodeCell. Right click, choose copy. Go to gvim. Paste. Observer CodeCell code contents being pasted instead of the region you had marked. CodeCell output is omitted.

Copying parts of the code cell on the other hand works as expected. Also the copy/pasting between notebooks does work, and also moves the output.

takluyver commented 8 years ago

Is there anything special about the way you're marking text? I'm testing locally with Firefox 45.0.2, marking text with the mouse, then right-clicking, copy, and pasting it into another application (I don't have gvim, but I think it's unlikely that that's the issue), and it's working fine for me.

takluyver commented 8 years ago

Can you mark some text, open up the browser's JS console, and run

window.getSelection().isCollapsed

When there's a text selection, that should evaluate to false, in which case we defer to the default copy action. If it evaluates to true (i.e. no text is selected) we copy the selected cells instead.

TyberiusPrime commented 8 years ago

Nothing special about marking the text. window.getSelection().isCollapsed is false when text is marked in the output section of a cell, but true when nothing is marked, or when text in the editor itself is marked.

Is it possible this is related to my window manager (i3)?

takluyver commented 8 years ago

I don't see how it could be related to the window manager, though anything's possible. window.getSelection().isCollapsed is what we check before handling a copy event, so if that's false, I don't know how we can be copying cells.

TyberiusPrime commented 8 years ago

I'm sorry for (probably) wasting your time - I've inspected notebook/clipboard.js inside my browser, and it actually lacks the isCollapsed check!

Now I gotta figure out why pip install git://... gave me an old version on what's supposed to be a new docker.

takluyver commented 8 years ago

Is it possible that docker is caching the result of that command, assuming it will do the same thing every time?

TyberiusPrime commented 8 years ago

I can exclude that - the docker actually has the new code in dist_packages/notebook/static/notebook/js/clipboard.js - so it's either browser caching or the js build.

The browser shows the file being in something called 'webpack'...

takluyver commented 8 years ago

Webpack is the JS builder/minifier we use. That should be run as part of installation from source.