From b348774871aefa99a5f1bb803ccfcf9515dc3209 Mon Sep 17 00:00:00 2001 From: Macy Abbey Date: Fri, 31 Oct 2014 10:59:58 -0700 Subject: [PATCH 1/2] Fix for issue #51, where the context menu paste event does not work in firefox. --- src/term.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/term.js b/src/term.js index f26617d..487a776 100644 --- a/src/term.js +++ b/src/term.js @@ -477,6 +477,8 @@ Terminal.prototype.initGlobal = function() { if (this.useStyle) { Terminal.insertStyle(document, this.colors[256], this.colors[257]); } + + this.fixFirefoxPaste(); }; /** @@ -539,6 +541,9 @@ Terminal.bindKeys = function(document) { // If we click somewhere other than a // terminal, unfocus the terminal. on(document, 'mousedown', function(ev) { + + Terminal.disableDesignMode(); + if (!Terminal.focus) return; var el = ev.target || ev.srcElement; @@ -597,6 +602,39 @@ Terminal.bindCopy = function(document) { }); }; +/** + * We set design mode because in firefox, this is the only way + * to get the paste event to fire because of this bug: + * https://bugzilla.mozilla.org/show_bug.cgi?id=846674 + * + */ +Terminal.prototype.fixFirefoxPaste = function () { + var window = document.defaultView; + + function disableDesignMode () { + if (Terminal.setDesignMode) { + document.designMode = Terminal.originalDesignMode; + Terminal.setDesignMode = false; + } + } + + function enableDesignMode () { + Terminal.originalDesignMode = document.designMode; + Terminal.setDesignMode = true; + document.designMode = "on"; + } + + //When a right click menu is available, enable design mode so the paste event will fire. + on(document, 'contextmenu', enableDesignMode); + + //Make sure we snap out of design mode after any action that would hide the context menu + //and actually allow the user to start modifying the document. + on(window, 'blur', disableDesignMode); + on(document, 'mousedown', disableDesignMode, true); + on(window, 'paste', disableDesignMode, true); +}; + + /** * Fix Mobile */ From 07ced44af3eaf7ff56b3abc6cf1196541c0b8b1d Mon Sep 17 00:00:00 2001 From: Macy Abbey Date: Fri, 31 Oct 2014 11:02:13 -0700 Subject: [PATCH 2/2] Removing unnessecary function call. --- src/term.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/term.js b/src/term.js index 487a776..af26b31 100644 --- a/src/term.js +++ b/src/term.js @@ -541,9 +541,6 @@ Terminal.bindKeys = function(document) { // If we click somewhere other than a // terminal, unfocus the terminal. on(document, 'mousedown', function(ev) { - - Terminal.disableDesignMode(); - if (!Terminal.focus) return; var el = ev.target || ev.srcElement;