From b8f1241bca274c6a087ce0f5ac586bd873c5857c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 23 Jul 2013 10:38:54 -0500 Subject: [PATCH] fix scrolling glitch. --- lib/widget.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 0d434c7..222d1af 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -3243,7 +3243,8 @@ ScrollableBox.prototype.scroll = function(offset, always) { , i , max , emax - , t; + , t + , l; if (diff === 0) { return this.emit('scroll'); @@ -3257,6 +3258,7 @@ ScrollableBox.prototype.scroll = function(offset, always) { max = this._clines.length - (this.height - this.iheight); if (max < 0) max = 0; emax = this._scrollBottom() - (this.height - this.iheight); + if (emax < 0) emax = 0; this.childBase = Math.min(this.childBase, Math.max(emax, max)); diff = this.childBase - base; @@ -3268,13 +3270,13 @@ ScrollableBox.prototype.scroll = function(offset, always) { } if (diff > 0) { - for (i = base; i < this.childBase; i++) { - if (!this._clines[i]) continue; + l = Math.min(this.childBase, this._clines.length); + for (i = base; i < l; i++) { this.contentIndex += this._clines[i].length + 1; } } else { - for (i = base - 1; i >= this.childBase; i--) { - if (!this._clines[i]) continue; + l = Math.min(this.childBase, this._clines.length); + for (i = base - 1; i >= l; i--) { this.contentIndex -= this._clines[i].length + 1; } } @@ -3300,9 +3302,9 @@ ScrollableBox.prototype.scroll = function(offset, always) { }; ScrollableBox.prototype._recalculateIndex = function() { - var max, emax, i, t; + var max, emax, i, t, l; - if (this.detached || !this.scrollabe) { + if (this.detached || !this.scrollable) { this.contentIndex = 0; return 0; } @@ -3310,6 +3312,7 @@ ScrollableBox.prototype._recalculateIndex = function() { max = this._clines.length - (this.height - this.iheight); if (max < 0) max = 0; emax = this._scrollBottom() - (this.height - this.iheight); + if (emax < 0) emax = 0; this.childBase = Math.min(this.childBase, Math.max(emax, max)); @@ -3319,8 +3322,8 @@ ScrollableBox.prototype._recalculateIndex = function() { this.childBase = this.baseLimit; } - for (i = 0, t = 0; i < this.childBase; i++) { - if (!this._clines[i]) continue; + l = Math.min(this.childBase, this._clines.length); + for (i = 0, t = 0; i < l; i++) { t += this._clines[i].length + 1; } @@ -4215,8 +4218,8 @@ Textarea.prototype._listener = function(ch, key) { Textarea.prototype._typeScroll = function() { // XXX Workaround - var width = this.height - this.iheight; - if (this._clines.length - this.childBase > width) { + var height = this.height - this.iheight; + if (this._clines.length - this.childBase > height) { //this.setContent(this.value + '\n'); this.scroll(this._clines.length); }