diff --git a/lib/widget.js b/lib/widget.js index cff2474..534a7f8 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -650,7 +650,7 @@ Box.prototype.render = function(stop) { , cell , attr , ch - , ci = 0 + , ci = this.contentIndex || 0 , cl = this.content.length , battr , dattr @@ -681,26 +681,6 @@ Box.prototype.render = function(stop) { } } - // Scroll the content - if (this.childBase != null) { - var cb = this.childBase - , xxl = xl - (this.border ? 1 : 0) - , xxi; - while (cb--) { - for (xxi = xi + (this.border ? 1 : 0); xxi < xxl; xxi++) { - if (this.content[ci] === '\n' || this.content[ci] === '\r') { - ci++; - break; - } else if (this.content[ci] === '\x1b') { - for (; ci < this.content.length; ci++) { - if (this.content[ci] === 'm') break; - } - } - ci++; - } - } - } - var ret = { xi: xi, xl: xl, @@ -819,7 +799,7 @@ Text.prototype.render = function(stop) { , cell , attr , ch - , ci = 0 + , ci = this.contentIndex || 0 , cl = this.content.length , ended = -1 , dattr @@ -1163,10 +1143,44 @@ function ScrollableText(options) { self.screen.render(); }); } + + this.contentIndex = 0; } ScrollableText.prototype.__proto__ = ScrollableBox.prototype; +ScrollableText.prototype._scroll = ScrollableText.prototype.scroll; +ScrollableText.prototype.scroll = function(offset) { + var ret = this._scroll(offset); + + if (this.content != null) { + var cb = this.childBase + , data = this.render(true) + , xi = data.xi + , xl = data.xl + , xxl = xl - (this.border ? 1 : 0) + , xxi + , ci = 0; + + while (cb--) { + for (xxi = xi + (this.border ? 1 : 0); xxi < xxl; xxi++) { + if (this.content[ci] === '\n' || this.content[ci] === '\r') { + ci++; + break; + } else if (this.content[ci] === '\x1b') { + for (; ci < this.content.length; ci++) { + if (this.content[ci] === 'm') break; + } + } + ci++; + } + } + this.contentIndex = ci; + } + + return ret; +}; + /** * Input */