From c491f7d2e1b7f6f95d6f5198cd72d766a3846336 Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Sun, 7 May 2017 14:57:56 -0700 Subject: [PATCH] re-implement `clear`, make it not buggy, fix CMD+K (#1796) --- lib/components/term.js | 9 +-------- lib/hterm.js | 43 ------------------------------------------ 2 files changed, 1 insertion(+), 51 deletions(-) diff --git a/lib/components/term.js b/lib/components/term.js index f886d2b1..15b64824 100644 --- a/lib/components/term.js +++ b/lib/components/term.js @@ -177,14 +177,7 @@ export default class Term extends Component { } clear() { - this.term.clearPreserveCursorRow(); - - // 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'); - } + this.term.onVTKeystroke('\f'); } moveWordLeft() { diff --git a/lib/hterm.js b/lib/hterm.js index 4be16404..6282e77e 100644 --- a/lib/hterm.js +++ b/lib/hterm.js @@ -260,49 +260,6 @@ hterm.Keyboard.prototype.onKeyDown_ = function (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_; hterm.Terminal.prototype.onMouse_ = function (e) { // override `preventDefault` to not actually