diff --git a/lib/widget.js b/lib/widget.js index c808870..b0f365d 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -1674,9 +1674,6 @@ ScrollableText.prototype.scroll = function(offset) { // 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. - // TODO: Possibly map _clines into line lengths only to save memory. if (this.content != null) { w = this.width - (this.border ? 2 : 0); if (this._clines == null || this._clines.width !== w) { @@ -1714,8 +1711,11 @@ ScrollableText.prototype._recalculateIndex = function() { this._clines = wrapContent(this.content, this.width - (this.border ? 2 : 0)); this._pcontent = this._clines.join('\n'); - if (this.childBase > this._clines.length - 1) { - this.childBase = this._clines.length - 1; + var max = this._clines.length - 1 - (this.height - (this.border ? 2 : 0)); + if (max < 0) max = 0; + + if (this.childBase > max) { + this.childBase = max; } for (var i = 0, t = 0; i < this.childBase; i++) {