From 4455bcfc8f199e5b971aa40d2580c33a403c15c2 Mon Sep 17 00:00:00 2001 From: nmadhum <nmadhum@deshaw.com> Date: Mon, 27 Nov 2017 05:34:08 -0500 Subject: [PATCH] Allow programmatic copy to clipboard --- notebook/static/notebook/js/clipboard.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/notebook/static/notebook/js/clipboard.js b/notebook/static/notebook/js/clipboard.js index b5248dd23..a15bae0f8 100644 --- a/notebook/static/notebook/js/clipboard.js +++ b/notebook/static/notebook/js/clipboard.js @@ -34,10 +34,18 @@ function load_json(clipboard) { return JSON.parse(s.slice(pix + jcbprefix.length, six)); } +function isProgrammaticCopy(event) { + return (typeof(event.target.selectionStart) !== 'undefined' + && typeof(event.target.selectionEnd) !== 'undefined' + && ((event.target.selectionEnd - event.target.selectionStart) > 0)); +} + function copy(event) { if ((Jupyter.notebook.mode !== 'command') || // window.getSelection checks if text is selected, e.g. in output - !window.getSelection().isCollapsed) { + !window.getSelection().isCollapsed || + // Allow programmatic copy + isProgrammaticCopy(event)) { return; } var selecn = Jupyter.notebook.get_selected_cells().map(