From 456d67c53706974fb53f6f789fd74a450c05baae Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Fri, 25 Nov 2016 01:35:39 -0800 Subject: [PATCH] make text selectable from terminal --- web/app/ui/terminal.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/web/app/ui/terminal.js b/web/app/ui/terminal.js index cee41b55..30f65217 100644 --- a/web/app/ui/terminal.js +++ b/web/app/ui/terminal.js @@ -2,11 +2,13 @@ export function Terminal(win, commandProcessor, variantsSupplier) { this.win = win; this.out = win.root.find('.terminal-output'); const input = win.root.find('.terminal-input input'); - + this.input = input; + win.onShowCallback = function() { input.focus(); }; - win.root.click(() => input.focus()); + this.makeAlwaysFocusable(); + this.history = []; this.historyPointer = 0; const setHistory = () => { @@ -77,12 +79,28 @@ export function Terminal(win, commandProcessor, variantsSupplier) { }); } +Terminal.prototype.makeAlwaysFocusable = function() { + let wasMove = false; + this.win.root.mousedown(() => { + wasMove = false; + return true; + }); + this.win.root.mousemove(() => { + wasMove = true; + return true; + }); + this.win.root.mouseup(() => { + if (!wasMove) this.input.focus(); + return true; + }); +}; + Terminal.prototype.scrollToTheEnd = function() { this.out.parent().scrollTop(this.out.height()); }; Terminal.prototype.print = function(text) { - this.win.root.find('.terminal-output').append($('
', {text, 'class': 'terminal-commandResult'})); + this.out.append($('
', {text, 'class': 'terminal-commandResult'})); this.scrollToTheEnd(); };