Merge pull request #336 from sourcelair/issue-#216-no-auto-scroll-on-output

Stop auto scrolling to bottom on output
This commit is contained in:
Paris Kasidiaris
2016-11-04 19:55:07 +00:00
committed by GitHub
2 changed files with 40 additions and 9 deletions
+21 -9
View File
@@ -234,6 +234,9 @@ function Terminal(options) {
this.tabs;
this.setupStops();
// Store if user went browsing history in scrollback
this.userScrolling = false;
}
inherits(Terminal, EventEmitter);
@@ -1253,7 +1256,9 @@ Terminal.prototype.scroll = function() {
this.lines = this.lines.slice(-(this.ybase + this.rows) + 1);
}
this.ydisp = this.ybase;
if (!this.userScrolling) {
this.ydisp = this.ybase;
}
// last line
row = this.ybase + this.rows - 1;
@@ -1275,7 +1280,9 @@ Terminal.prototype.scroll = function() {
if (this.scrollTop !== 0) {
if (this.ybase !== 0) {
this.ybase--;
this.ydisp = this.ybase;
if (!this.userScrolling) {
this.ydisp = this.ybase;
}
}
this.lines.splice(this.ybase + this.scrollTop, 1);
}
@@ -1295,6 +1302,12 @@ Terminal.prototype.scroll = function() {
* viewport originally.
*/
Terminal.prototype.scrollDisp = function(disp, suppressScrollEvent) {
if (disp < 0) {
this.userScrolling = true;
} else if (disp + this.ydisp >= this.ybase) {
this.userScrolling = false;
}
this.ydisp += disp;
if (this.ydisp > this.ybase) {
@@ -1342,12 +1355,6 @@ Terminal.prototype.write = function(data) {
this.refreshStart = this.y;
this.refreshEnd = this.y;
if (this.ybase !== this.ydisp) {
this.ydisp = this.ybase;
this.emit('scroll', this.ydisp);
this.maxRange();
}
// apply leftover surrogate high from last write
if (this.surrogate_high) {
data = this.surrogate_high + data;
@@ -2413,6 +2420,11 @@ Terminal.prototype.attachCustomKeydownHandler = function(customKeydownHandler) {
* @param {KeyboardEvent} ev The keydown event to be handled.
*/
Terminal.prototype.keyDown = function(ev) {
// Scroll down to prompt, whenever the user presses a key.
if (this.ybase !== this.ydisp) {
this.scrollToBottom();
}
if (this.customKeydownHandler && this.customKeydownHandler(ev) === false) {
return false;
}
@@ -2965,7 +2977,7 @@ Terminal.prototype.updateRange = function(y) {
};
/**
* Set the range of refreshing to the maximyum value
* Set the range of refreshing to the maximum value
*/
Terminal.prototype.maxRange = function() {
this.refreshStart = 0;
+19
View File
@@ -181,6 +181,25 @@ describe('xterm.js', function() {
assert.equal(xterm.ydisp, startYDisp);
});
});
describe('keyDown', function () {
it('should scroll down, when a key is pressed and terminal is scrolled up', function () {
var terminal = new Terminal();
// Do not process the keyDown event, to avoid side-effects
terminal.attachCustomKeydownHandler(function () {
return false;
});
terminal.ydisp = 0;
terminal.ybase = 40;
terminal.keyDown();
// Ensure that now the terminal is scrolled to bottom
assert.equal(terminal.ydisp, terminal.ybase);
});
});
});
describe('evaluateKeyEscapeSequence', function() {