mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-16 05:38:41 -09:00
Path matching selection on dblClick
This commit is contained in:
parent
56f718a0f4
commit
ed4a2c66da
2 changed files with 14 additions and 8 deletions
12
lib/hterm.js
12
lib/hterm.js
|
|
@ -1,17 +1,13 @@
|
||||||
import { hterm, lib } from 'hterm-umdjs';
|
import { hterm, lib } from 'hterm-umdjs';
|
||||||
|
const selection = require('./utils/selection');
|
||||||
|
|
||||||
hterm.defaultStorage = new lib.Storage.Memory();
|
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
|
// override double click behavior to copy
|
||||||
const oldMouse = hterm.Terminal.prototype.onMouse_;
|
const oldMouse = hterm.Terminal.prototype.onMouse_;
|
||||||
hterm.Terminal.prototype.onMouse_ = function (e) {
|
hterm.Terminal.prototype.onMouse_ = function (e) {
|
||||||
if ('dblclick' === e.type) {
|
if ('dblclick' === e.type) {
|
||||||
|
selection.expand(this);
|
||||||
console.log('[hyperterm+hterm] ignore double click');
|
console.log('[hyperterm+hterm] ignore double click');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +90,7 @@ hterm.Keyboard.prototype.onKeyDown_ = function (e) {
|
||||||
} else {
|
} else {
|
||||||
// Test for valid keys in order to clear the terminal selection
|
// Test for valid keys in order to clear the terminal selection
|
||||||
if ((!e.ctrlKey || e.code !== 'ControlLeft') && !e.shiftKey && e.code !== 'CapsLock') {
|
if ((!e.ctrlKey || e.code !== 'ControlLeft') && !e.shiftKey && e.code !== 'CapsLock') {
|
||||||
this.terminal.clearSelection();
|
selection.clear(this.terminal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return oldKeyDown.call(this, e);
|
return oldKeyDown.call(this, e);
|
||||||
|
|
@ -105,7 +101,7 @@ hterm.Keyboard.prototype.onKeyPress_ = function (e) {
|
||||||
if (e.metaKey) {
|
if (e.metaKey) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
this.terminal.clearSelection();
|
selection.clear(this.terminal);
|
||||||
}
|
}
|
||||||
return oldKeyPress.call(this, e);
|
return oldKeyPress.call(this, e);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
10
lib/utils/selection.js
Normal file
10
lib/utils/selection.js
Normal file
|
|
@ -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());
|
||||||
|
};
|
||||||
Loading…
Reference in a new issue