From ed4a2c66da9f83fb96cab745b1eb90f0e898027b Mon Sep 17 00:00:00 2001 From: ppot Date: Wed, 17 Aug 2016 21:45:18 -0400 Subject: [PATCH] Path matching selection on dblClick --- lib/hterm.js | 12 ++++-------- lib/utils/selection.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 lib/utils/selection.js diff --git a/lib/hterm.js b/lib/hterm.js index 9b25d5e7..531655ea 100644 --- a/lib/hterm.js +++ b/lib/hterm.js @@ -1,17 +1,13 @@ import { hterm, lib } from 'hterm-umdjs'; +const selection = require('./utils/selection'); hterm.defaultStorage = new lib.Storage.Memory(); -// clear selection range of current selected term view -// Fix event when terminal text is selected and keyboard action is invoked -hterm.Terminal.prototype.clearSelection = function () { - this.document_.getSelection().removeAllRanges(); -}; - // override double click behavior to copy const oldMouse = hterm.Terminal.prototype.onMouse_; hterm.Terminal.prototype.onMouse_ = function (e) { if ('dblclick' === e.type) { + selection.expand(this); console.log('[hyperterm+hterm] ignore double click'); return; } @@ -94,7 +90,7 @@ hterm.Keyboard.prototype.onKeyDown_ = function (e) { } else { // Test for valid keys in order to clear the terminal selection if ((!e.ctrlKey || e.code !== 'ControlLeft') && !e.shiftKey && e.code !== 'CapsLock') { - this.terminal.clearSelection(); + selection.clear(this.terminal); } } return oldKeyDown.call(this, e); @@ -105,7 +101,7 @@ hterm.Keyboard.prototype.onKeyPress_ = function (e) { if (e.metaKey) { return; } else { - this.terminal.clearSelection(); + selection.clear(this.terminal); } return oldKeyPress.call(this, e); }; diff --git a/lib/utils/selection.js b/lib/utils/selection.js new file mode 100644 index 00000000..001b33f8 --- /dev/null +++ b/lib/utils/selection.js @@ -0,0 +1,10 @@ +// clear selection range of current selected term view +// Fix event when terminal text is selected and keyboard action is invoked +exports.clear = function (terminal) { + terminal.document_.getSelection().removeAllRanges(); +}; + +// Use selection expand upon dblclick +exports.expand = function (terminal) { + terminal.screen_.expandSelection(terminal.document_.getSelection()); +};