From 72eeb99ad6f234467d561e2ebfc79343c35aa2b2 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Tue, 12 Apr 2016 10:43:04 -0700 Subject: [PATCH] Respect keyboard manager state in clipboard logic --- notebook/static/notebook/js/clipboard.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/notebook/static/notebook/js/clipboard.js b/notebook/static/notebook/js/clipboard.js index f1228c8f2..63193df03 100644 --- a/notebook/static/notebook/js/clipboard.js +++ b/notebook/static/notebook/js/clipboard.js @@ -68,17 +68,16 @@ function paste(event) { event.preventDefault(); } -function paste_direct(event) { +function notebookOnlyEvent(callback) { + // Only call the callback to redirect the event if the notebook should be + // handling the events, at the descretion of the keyboard manager. // If the focus is in a text widget or something (kbmanager disabled), - // allow the default paste event. - // The paste dialog implementation (for Firefox) can't do this check, - // because the keyboard manager will be disabled for the dialog when we try - // to paste. In that case, the shortcut to trigger the dialog will be - // inactive anyway when a widget or something is focussed, so we don't - // need the explicit check. - if (Jupyter.keyboard_manager.enabled) { - paste(event); - } + // allow the default event. + return function() { + if (Jupyter.keyboard_manager.enabled) { + callback.apply(this, arguments); + } + }; } function needs_text_box_for_paste_event() { @@ -137,11 +136,11 @@ function setup_paste_dialog() { // Set clipboard event listeners on the document. return {setup_clipboard_events: function() { - document.addEventListener('copy', copy); + document.addEventListener('copy', notebookOnlyEvent(copy)); if (needs_text_box_for_paste_event()) { setup_paste_dialog(); } else { - document.addEventListener('paste', paste_direct); + document.addEventListener('paste', notebookOnlyEvent(paste)); } }}; });