Skip to content

Commit b1e5f72

Browse files
authored
Merge pull request #3088 from Madhu94/detect-programmatic-copy
Allow programmatic copy to clipboard
2 parents cbf7db7 + 4455bcf commit b1e5f72

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

notebook/static/notebook/js/clipboard.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ function load_json(clipboard) {
3434
return JSON.parse(s.slice(pix + jcbprefix.length, six));
3535
}
3636

37+
function isProgrammaticCopy(event) {
38+
return (typeof(event.target.selectionStart) !== 'undefined'
39+
&& typeof(event.target.selectionEnd) !== 'undefined'
40+
&& ((event.target.selectionEnd - event.target.selectionStart) > 0));
41+
}
42+
3743
function copy(event) {
3844
if ((Jupyter.notebook.mode !== 'command') ||
3945
// window.getSelection checks if text is selected, e.g. in output
40-
!window.getSelection().isCollapsed) {
46+
!window.getSelection().isCollapsed ||
47+
// Allow programmatic copy
48+
isProgrammaticCopy(event)) {
4149
return;
4250
}
4351
var selecn = Jupyter.notebook.get_selected_cells().map(

0 commit comments

Comments
 (0)