diff --git a/lib/widget.js b/lib/widget.js index 1a3d37c..0d434c7 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -2606,15 +2606,12 @@ Box.prototype._getCoords = function(get) { // this.parent.lpos.yi - which was saved after it's render() **with the // childBase subtracted!!!!*** This means nested elements within // a scrollable box are screwy unless we do this. + // We only do this when `get` is true, because that gets this.parent.lpos. + // If it's false, the parent's position is calculated on the spot. var cb = el.childBase; if (get) { - var el_ = this; - // Do we need to get every parent? - while (el_ = el_.parent) { - if (el_ === el) break; - yi += el_.lpos.cb; - yl += el_.lpos.cb; - } + yi += this.parent.lpos.cb; + yl += this.parent.lpos.cb; } ryi = yi - el._getTop(get) - el.itop; @@ -3202,7 +3199,7 @@ ScrollableBox.prototype.scrollTo = function(offset) { return this.scroll(offset - (this.childBase + this.childOffset)); }; -ScrollableBox.prototype.scroll = function(offset) { +ScrollableBox.prototype.scroll = function(offset, always) { if (!this.scrollable) return; // Handle scrolling. @@ -3213,7 +3210,7 @@ ScrollableBox.prototype.scroll = function(offset) { , t , b; - if (this.alwaysScroll) { + if (this.alwaysScroll || always) { // Semi-workaround this.childOffset = offset > 0 ? visible - 1 + offset @@ -4033,7 +4030,6 @@ Textbox.prototype.render = function() { // setContent is necessary to clear the area in case // .shrink is being used and the new content is smaller. // Could technically optimize this. - if (!this._getCoords(true)) return; if (this.secret) { this.setContent(''); return this._render(); @@ -4090,7 +4086,7 @@ Textarea.prototype.updateCursor = function() { return; } - var lpos = this.getCoords(); + var lpos = this._getCoords(); if (!lpos) return; var last = this._clines[this._clines.length-1] @@ -4646,7 +4642,6 @@ Checkbox.prototype.type = 'checkbox'; Checkbox.prototype._render = Checkbox.prototype.render; Checkbox.prototype.render = function() { - //if (!this._getCoords(true)) return; if (this.type === 'radio-button') { this.setContent('(' + (this.checked ? '*' : ' ') + ') ' + this.text); } else { @@ -5223,7 +5218,6 @@ Listbar.prototype.setItems = function(commands) { Listbar.prototype._render = Listbar.prototype.render; Listbar.prototype.render = function() { - if (!this._getCoords(true)) return; var self = this , drawn = 0; diff --git a/test/widget-form.js b/test/widget-form.js index 1811da6..c79ddbf 100644 --- a/test/widget-form.js +++ b/test/widget-form.js @@ -30,12 +30,12 @@ form.on('submit', function(data) { }); form.key('d', function() { - form.scroll(1); + form.scroll(1, true); screen.render(); }); form.key('u', function() { - form.scroll(-1); + form.scroll(-1, true); screen.render(); }); @@ -143,6 +143,46 @@ submit.on('press', function() { form.submit(); }); +var box1 = blessed.box({ + parent: form, + left: 1, + top: 10, + height: 10, + width: 10, + content: 'one', + bg: 'cyan' +}); + +var box2 = blessed.box({ + parent: box1, + left: 1, + top: 2, + height: 8, + width: 9, + content: 'two', + bg: 'magenta' +}); + +var box3 = blessed.box({ + parent: box2, + left: 1, + top: 2, + height: 6, + width: 8, + content: 'three', + bg: 'yellow' +}); + +var box4 = blessed.box({ + parent: box3, + left: 1, + top: 2, + height: 4, + width: 7, + content: 'four', + bg: 'blue' +}); + var output = blessed.scrollabletext({ parent: screen, mouse: true,