cleanup recent scroll work. fix max.

This commit is contained in:
Christopher Jeffrey 2013-06-09 20:25:13 -05:00
parent ee739c6e7a
commit 07351bdcb0
1 changed files with 10 additions and 20 deletions

View File

@ -478,6 +478,7 @@ Screen.prototype.fillRegion = function(attr, ch, xi, xl, yi, yl) {
var lines = this.lines
, attr = attr || this.dattr
, ch = ch || ' '
, cell
, xx;
for (; yi < yl; yi++) {
@ -827,7 +828,7 @@ Box.prototype.render = function(stop) {
attr = dattr;
// Check previous line for escape codes.
if (this.childBase > 0 && this.content != null) {
if (this.childBase > 0 && this._content) {
var cci = ci - (this._content[this.childBase - 1].length + 1);
for (; cci < ci; cci++) {
if (this.content[cci] === '\x1b') {
@ -1285,13 +1286,13 @@ ScrollableText.prototype.scroll = function(offset) {
, max
, t;
if (diff === 0) {
return ret;
}
if (diff === 0) return ret;
// When scrolling text, we want to be able to handle SGR codes as well as line
// feeds. This allows us to take preformatted text output from other programs
// and put it in a scrollable text box.
// TODO: Move this into a separate function and call it from the constructor
// and setContent.
if (this.content != null) {
w = this.width - (this.border ? 2 : 0);
if (this.__content == null) this.__content = this.content;
@ -1300,20 +1301,12 @@ ScrollableText.prototype.scroll = function(offset) {
this.content = this._content.join('\n');
}
// Slow:
// this.contentIndex = this._content.slice(0, cb).join('\n').length;
// if (cb > 0) this.contentIndex++;
max = this._content.length - 1 - (this.height - (this.border ? 2 : 0));
if (cb > max) this.childBase = cb = max;
// Less slow:
//this.contentIndex = this._content.slice(0, cb).reduce(function(total, line) {
// return total + line.length + 1;
//}, 0);
// Fast:
//for (i = 0, t = 0; i < cb; i++) {
// t += this._content[i].length + 1;
//}
//this.contentIndex = t;
// Simpler:
// for (i = 0, t = 0; i < cb; i++) t += this._content[i].length + 1;
// this.contentIndex = t;
// Faster:
if (diff > 0) {
@ -1321,9 +1314,6 @@ ScrollableText.prototype.scroll = function(offset) {
} else {
for (i = base - 1; i >= cb; i--) this.contentIndex -= this._content[i].length + 1;
}
max = this._content.length - 1 - (this.height - (this.border ? 2 : 0));
if (cb > max) this.childBase = max;
}
return ret;