mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Fix ScrollPort SelectAll
This commit is contained in:
parent
ed4a2c66da
commit
3813d27d5f
4 changed files with 49 additions and 3 deletions
|
|
@ -145,6 +145,10 @@ export default class Term extends Component {
|
|||
this.term.onVTKeystroke('\x05');
|
||||
}
|
||||
|
||||
selectAll () {
|
||||
this.term.selectAll();
|
||||
}
|
||||
|
||||
getTermDocument () {
|
||||
return this.term.document_;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ class HyperTerm extends Component {
|
|||
keys.bind('command+backspace', bound('deleteLine'));
|
||||
keys.bind('command+left', bound('moveToStart'));
|
||||
keys.bind('command+right', bound('moveToEnd'));
|
||||
keys.bind('command+a', bound('selectAll'));
|
||||
this.keys = keys;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,18 @@ const selection = require('./utils/selection');
|
|||
|
||||
hterm.defaultStorage = new lib.Storage.Memory();
|
||||
|
||||
// Provide selectAll to terminal viewport
|
||||
hterm.Terminal.prototype.selectAll = function () {
|
||||
// We need to clear dom range to reset anchorNode
|
||||
selection.clear(this);
|
||||
selection.all(this);
|
||||
};
|
||||
|
||||
// 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);
|
||||
selection.extend(this);
|
||||
console.log('[hyperterm+hterm] ignore double click');
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,41 @@ exports.clear = function (terminal) {
|
|||
terminal.document_.getSelection().removeAllRanges();
|
||||
};
|
||||
|
||||
// Use selection expand upon dblclick
|
||||
exports.expand = function (terminal) {
|
||||
// Use selection extend upon dblclick
|
||||
exports.extend = function (terminal) {
|
||||
terminal.screen_.expandSelection(terminal.document_.getSelection());
|
||||
};
|
||||
|
||||
// Fix a bug in ScrollPort selectAll behavior
|
||||
// Select all rows in the viewport
|
||||
exports.all = function (terminal) {
|
||||
let scrollPort = terminal.scrollPort_;
|
||||
let firstRow, lastRowIndex, lastRow;
|
||||
|
||||
if (scrollPort.topFold_.nextSibling.rowIndex !== 0) {
|
||||
while (scrollPort.topFold_.previousSibling) {
|
||||
scrollPort.rowNodes_.removeChild(scrollPort.topFold_.previousSibling);
|
||||
}
|
||||
|
||||
firstRow = scrollPort.fetchRowNode_(0);
|
||||
scrollPort.rowNodes_.insertBefore(firstRow, scrollPort.topFold_);
|
||||
scrollPort.syncRowNodesDimensions_();
|
||||
} else {
|
||||
firstRow = scrollPort.topFold_.nextSibling;
|
||||
}
|
||||
|
||||
lastRowIndex = scrollPort.rowProvider_.getRowCount() - 1;
|
||||
|
||||
if (scrollPort.bottomFold_.previousSibling.rowIndex !== lastRowIndex) {
|
||||
while (scrollPort.bottomFold_.nextSibling) {
|
||||
scrollPort.rowNodes_.removeChild(scrollPort.bottomFold_.nextSibling);
|
||||
}
|
||||
|
||||
lastRow = scrollPort.fetchRowNode_(lastRowIndex);
|
||||
scrollPort.rowNodes_.appendChild(lastRow);
|
||||
} else {
|
||||
lastRow = scrollPort.bottomFold_.previousSibling.rowIndex;
|
||||
}
|
||||
|
||||
scrollPort.selection.sync();
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue