Only do copy when the editor has focus.
clipboardonfocus
Only do copy when the editor has focus.
--- a/frontend/js/bespin/editor/clipboard.js
+++ b/frontend/js/bespin/editor/clipboard.js
@@ -90,17 +90,17 @@ dojo.mixin(bespin.editor.clipboard, {
dojo.declare("bespin.editor.clipboard.DOMEvents", null, {
install: function(editor) {
// * Defensively stop doing copy/cut/paste magic if you are in the command line
var stopAction = function(e) {
return e.target.id == "command";
};
var editorHasFocus = function() {
- return true;
+ return editor.focus;
};
var focuser = this.focuser = bespin.editor.clipboard.createHiddenTextarea();
var onfocuser = false;
// Copy
this.beforecopyHandle = dojo.connect(document.body, "onbeforecopy", function(e) {
if ((!editorHasFocus() && !onfocuser) || stopAction(e)) return;
@@ -111,17 +111,17 @@ dojo.declare("bespin.editor.clipboard.DO
focuser.focus();
focuser.select();
// and we are now on focuser
onfocuser = true;
});
this.copyHandle = dojo.connect(document.body, "oncopy", function(e) {
- if (!editorHasFocus() && !onFocuser) return;
+ if (!editorHasFocus() && !onfocuser) return;
if (stopAction(e)) return;
var selectionText = editor.getSelectionAsText();
if (selectionText && selectionText != '') {
e.clipboardData.setData('text/plain', selectionText);
dojo.stopEvent(e); // need a full stop, otherwise someone else will try to set copy data.
}
@@ -139,17 +139,17 @@ dojo.declare("bespin.editor.clipboard.DO
focuser.focus();
focuser.select();
// and we are now on focuser
onfocuser = true;
});
this.cutHandle = dojo.connect(document, "cut", function(e) {
- if (!editorHasFocus() && !onFocuser) return;
+ if (!editorHasFocus() && !onfocuser) return;
if (stopAction(e)) return;
var selectionObject = editor.getSelection();
if (selectionObject) {
var selectionText = editor.model.getChunk(selectionObject);
if (selectionText && selectionText != '') {