mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-16 13:48:41 -09:00
re-implement clear, make it not buggy, fix CMD+K (#1796)
This commit is contained in:
parent
fc51f97283
commit
c491f7d2e1
2 changed files with 1 additions and 51 deletions
|
|
@ -177,14 +177,7 @@ export default class Term extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
this.term.clearPreserveCursorRow();
|
this.term.onVTKeystroke('\f');
|
||||||
|
|
||||||
// If cursor is still not at the top, a command is probably
|
|
||||||
// running and we'd like to delete the whole screen.
|
|
||||||
// Move cursor to top
|
|
||||||
if (this.term.getCursorRow() !== 0) {
|
|
||||||
this.write('\x1B[0;0H\x1B[2J');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
moveWordLeft() {
|
moveWordLeft() {
|
||||||
|
|
|
||||||
43
lib/hterm.js
43
lib/hterm.js
|
|
@ -260,49 +260,6 @@ hterm.Keyboard.prototype.onKeyDown_ = function (e) {
|
||||||
return oldKeyDown.call(this, e);
|
return oldKeyDown.call(this, e);
|
||||||
};
|
};
|
||||||
|
|
||||||
// we re-implement `wipeContents` to preserve the line
|
|
||||||
// and cursor position that the client is in.
|
|
||||||
// otherwise the user ends up with a completely clear
|
|
||||||
// screen which is really strange
|
|
||||||
hterm.Terminal.prototype.clearPreserveCursorRow = function () {
|
|
||||||
this.scrollbackRows_.length = 0;
|
|
||||||
this.scrollPort_.resetCache();
|
|
||||||
|
|
||||||
[this.primaryScreen_, this.alternateScreen_].forEach(screen => {
|
|
||||||
const bottom = screen.getHeight();
|
|
||||||
if (bottom > 0) {
|
|
||||||
this.renumberRows_(0, bottom);
|
|
||||||
|
|
||||||
const x = screen.cursorPosition.column;
|
|
||||||
const y = screen.cursorPosition.row;
|
|
||||||
|
|
||||||
if (x === 0) {
|
|
||||||
// Empty screen, nothing to do.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// here we move the row that the user was focused on
|
|
||||||
// to the top of the screen
|
|
||||||
this.moveRows_(y, 1, 0);
|
|
||||||
|
|
||||||
for (let i = 1; i < bottom; i++) {
|
|
||||||
screen.setCursorPosition(i, 0);
|
|
||||||
screen.clearCursorRow();
|
|
||||||
}
|
|
||||||
|
|
||||||
// we restore the cursor position
|
|
||||||
screen.setCursorPosition(0, x);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.syncCursorPosition_();
|
|
||||||
this.scrollPort_.invalidate();
|
|
||||||
|
|
||||||
// this will avoid a bug where the `wipeContents`
|
|
||||||
// hterm API doesn't send the scroll to the top
|
|
||||||
this.scrollPort_.redraw_();
|
|
||||||
};
|
|
||||||
|
|
||||||
const oldOnMouse = hterm.Terminal.prototype.onMouse_;
|
const oldOnMouse = hterm.Terminal.prototype.onMouse_;
|
||||||
hterm.Terminal.prototype.onMouse_ = function (e) {
|
hterm.Terminal.prototype.onMouse_ = function (e) {
|
||||||
// override `preventDefault` to not actually
|
// override `preventDefault` to not actually
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue