From 1f361b3f482fabb8f6dfa28f502f65019addf0d8 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Tue, 11 Feb 2014 16:54:11 +0100 Subject: [PATCH] Restore paste --- butterfly/static/coffees/term.coffee | 19 +++++++++++-------- butterfly/static/javascripts/main.js | 17 +++++++++++++++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/butterfly/static/coffees/term.coffee b/butterfly/static/coffees/term.coffee index 852f63b..7cfaf0d 100644 --- a/butterfly/static/coffees/term.coffee +++ b/butterfly/static/coffees/term.coffee @@ -25,7 +25,7 @@ class Terminal @rows = 24 @scrollback = 100000 @visualBell = 100 - @debug = true + @debug = not true @convertEol = false @termName = 'xterm' @@ -90,6 +90,13 @@ class Terminal @element.classList.add('blur') @element.classList.remove('focus') + paste: (ev) -> + if ev.clipboardData + @send(ev.clipboardData.getData('text/plain')) + else if window.clipboardData + @send(window.clipboardData.getData('Text')) + cancel(ev) + open: (parent) -> @parent = parent or @parent throw new Error('Terminal requires a parent element') unless @parent @@ -124,6 +131,7 @@ class Terminal addEventListener('keypress', @keyPress.bind(@)) addEventListener('focus', @focus.bind(@)) addEventListener('blur', @blur.bind(@)) + addEventListener('paste', @paste.bind(@)) destroy: -> @readable = false @@ -886,13 +894,8 @@ class Terminal return true if ev.keyCode > 15 and ev.keyCode < 19 # Handle shift insert and ctrl insert copy/paste usefull for typematrix keyboard - # TODO - # if ev.shiftKey and ev.keyCode is 45 - # @emit "paste" - # return true - # if ev.ctrlKey and ev.keyCode is 45 - # @emit "copy" - # return true + if (ev.shiftKey or ev.ctrlKey) and ev.keyCode is 45 + return true # Alt-z works as an escape to relay the following keys to the browser. # usefull to trigger browser shortcuts, i.e.: Alt+Z F5 to reload diff --git a/butterfly/static/javascripts/main.js b/butterfly/static/javascripts/main.js index 79eb423..efbf014 100644 --- a/butterfly/static/javascripts/main.js +++ b/butterfly/static/javascripts/main.js @@ -216,7 +216,7 @@ Terminal = (function() { this.rows = 24; this.scrollback = 100000; this.visualBell = 100; - this.debug = true; + this.debug = !true; this.convertEol = false; this.termName = 'xterm'; this.cursorBlink = true; @@ -285,6 +285,15 @@ Terminal = (function() { return this.element.classList.remove('focus'); }; + Terminal.prototype.paste = function(ev) { + if (ev.clipboardData) { + this.send(ev.clipboardData.getData('text/plain')); + } else if (window.clipboardData) { + this.send(window.clipboardData.getData('Text')); + } + return cancel(ev); + }; + Terminal.prototype.open = function(parent) { var div, i, _i, _ref; this.parent = parent || this.parent; @@ -311,7 +320,8 @@ Terminal = (function() { addEventListener('keydown', this.keyDown.bind(this)); addEventListener('keypress', this.keyPress.bind(this)); addEventListener('focus', this.focus.bind(this)); - return addEventListener('blur', this.blur.bind(this)); + addEventListener('blur', this.blur.bind(this)); + return addEventListener('paste', this.paste.bind(this)); }; Terminal.prototype.destroy = function() { @@ -1022,6 +1032,9 @@ Terminal = (function() { if (ev.keyCode > 15 && ev.keyCode < 19) { return true; } + if ((ev.shiftKey || ev.ctrlKey) && ev.keyCode === 45) { + return true; + } if (ev.altKey && ev.keyCode === 90 && !this.skipNextKey) { this.skipNextKey = true; return cancel(ev);