diff --git a/src/term.js b/src/term.js index ff235aa3..86534994 100644 --- a/src/term.js +++ b/src/term.js @@ -456,6 +456,8 @@ Terminal.prototype.initGlobal = function() { } Terminal._boundDocs.push(document); + Terminal.bindPaste(document); + Terminal.bindKeys(document); if (this.isIpad) { @@ -467,6 +469,28 @@ Terminal.prototype.initGlobal = function() { } }; +/** + * Bind to paste event + */ + +Terminal.bindPaste = function(document) { + // This seems to work well for ctrl-V and middle-click, + // even without the contentEditable workaround. + var window = document.defaultView; + on(window, 'paste', function(ev) { + var term = Terminal.focus; + if (!term) return; + if (ev.clipboardData) { + term.send(ev.clipboardData.getData('text/plain')); + } else if (term.context.clipboardData) { + term.send(term.context.clipboardData.getData('Text')); + } + // Not necessary. Do it anyway for good measure. + term.element.contentEditable = 'inherit'; + return cancel(ev); + }); +}; + /** * Global Events for key handling */ @@ -553,7 +577,7 @@ Terminal.insertStyle = function(document, bg, fg) { if (!head) return; var style = document.createElement('style'); - style.id = 'termjs-style'; + style.id = 'term-style'; // textContent doesn't work well with IE for