Skip to content

Commit ac70e49

Browse files
committed
Merge pull request #1342 from jdfreder/clipboardRespect
Respect keyboard manager state in clipboard logic
2 parents 4857a7d + 72eeb99 commit ac70e49

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

notebook/static/notebook/js/clipboard.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,16 @@ function paste(event) {
6868
event.preventDefault();
6969
}
7070

71-
function paste_direct(event) {
71+
function notebookOnlyEvent(callback) {
72+
// Only call the callback to redirect the event if the notebook should be
73+
// handling the events, at the descretion of the keyboard manager.
7274
// If the focus is in a text widget or something (kbmanager disabled),
73-
// allow the default paste event.
74-
// The paste dialog implementation (for Firefox) can't do this check,
75-
// because the keyboard manager will be disabled for the dialog when we try
76-
// to paste. In that case, the shortcut to trigger the dialog will be
77-
// inactive anyway when a widget or something is focussed, so we don't
78-
// need the explicit check.
79-
if (Jupyter.keyboard_manager.enabled) {
80-
paste(event);
81-
}
75+
// allow the default event.
76+
return function() {
77+
if (Jupyter.keyboard_manager.enabled) {
78+
callback.apply(this, arguments);
79+
}
80+
};
8281
}
8382

8483
function needs_text_box_for_paste_event() {
@@ -137,11 +136,11 @@ function setup_paste_dialog() {
137136

138137
// Set clipboard event listeners on the document.
139138
return {setup_clipboard_events: function() {
140-
document.addEventListener('copy', copy);
139+
document.addEventListener('copy', notebookOnlyEvent(copy));
141140
if (needs_text_box_for_paste_event()) {
142141
setup_paste_dialog();
143142
} else {
144-
document.addEventListener('paste', paste_direct);
143+
document.addEventListener('paste', notebookOnlyEvent(paste));
145144
}
146145
}};
147146
});

0 commit comments

Comments
 (0)