diff --git a/demo/main.js b/demo/main.js index d9bc9284..263ba168 100644 --- a/demo/main.js +++ b/demo/main.js @@ -15,7 +15,9 @@ term.writeln(''); term.prompt(); term.on('key', function (key, ev) { - var printable = (!ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey); + var printable = ( + !ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey + ); if (ev.keyCode == 13) { term.prompt(); diff --git a/src/xterm.js b/src/xterm.js index c9fec907..fd9d03a4 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -100,10 +100,11 @@ }; EventEmitter.prototype.once = function(type, listener) { + var self = this; function on() { var args = Array.prototype.slice.call(arguments); - this.removeListener(type, on); - return listener.apply(this, args); + self.removeListener(type, on); + return listener.apply(self, args); } on.listener = listener; return this.on(type, on); @@ -430,7 +431,6 @@ var text = ev.clipboardData.getData('text/plain'); term.handler(text); } - return term.cancel(ev, true); }); }; @@ -440,6 +440,16 @@ */ Terminal.bindKeys = function(term) { on(term.element, 'keydown', function(ev) { + /* + * Clear all selections if the key pressed was not among + * Shift, Alt, Cmd, Ctrl. + */ + var selection = window.getSelection(); + if (selection.toString() != '') { + if ([16, 17, 18, 91].indexOf(ev.keyCode) == -1) { + selection.removeAllRanges(); + } + } term.keyDown(ev); }, true); @@ -470,6 +480,17 @@ }; + Terminal.click = function (term) { + /* + * Do not perform the "drop" event. Altering the contents of the + * terminal with drag n drop is unwanted behavior. + */ + on(term.element, 'click', function (ev) { + term.cancel(ev, true); + }); + }; + + /* * Insert the given row to the terminal or produce a new one * if no row argument is passed. Return the inserted row. @@ -523,7 +544,6 @@ this.element.classList.add('xterm'); this.element.classList.add('xterm-theme-' + this.theme); this.element.setAttribute('tabindex', 0); - this.element.contentEditable = 'true'; this.element.spellcheck = 'false'; /*