cleanup render. ignore border option on scrollbar.

This commit is contained in:
Christopher Jeffrey 2013-06-25 18:23:15 -05:00
parent edc5535682
commit a1e9ec5a55

View File

@ -1338,16 +1338,16 @@ Box.prototype.render = function(stop) {
, cl = content.length , cl = content.length
, battr , battr
, dattr , dattr
, c; , c
, rtop
var rtop
, visible , visible
, hw , hw
, h , h
, w , w
, xll , xll
, yll , yll
, ret; , ret
, cci;
if (this.position.width) { if (this.position.width) {
xl = xi_ + this.width; xl = xi_ + this.width;
@ -1359,8 +1359,8 @@ Box.prototype.render = function(stop) {
// Check to make sure we're visible and inside of the visible scroll area. // Check to make sure we're visible and inside of the visible scroll area.
if (this.parent.childBase != null && (!this.parent.items || ~this.parent.items.indexOf(this))) { if (this.parent.childBase != null && (!this.parent.items || ~this.parent.items.indexOf(this))) {
var rtop = this.rtop - (this.parent.border ? 1 : 0) rtop = this.rtop - (this.parent.border ? 1 : 0);
, visible = this.parent.height - (this.parent.border ? 2 : 0); visible = this.parent.height - (this.parent.border ? 2 : 0);
yi_ -= this.parent.childBase; yi_ -= this.parent.childBase;
yl = Math.min(yl, this.screen.rows - this.parent.bottom - (this.parent.border ? 1 : 0)); yl = Math.min(yl, this.screen.rows - this.parent.bottom - (this.parent.border ? 1 : 0));
@ -1368,6 +1368,7 @@ Box.prototype.render = function(stop) {
if (rtop - this.parent.childBase < 0) { if (rtop - this.parent.childBase < 0) {
return; return;
} }
if (rtop - this.parent.childBase >= visible) { if (rtop - this.parent.childBase >= visible) {
return; return;
} }
@ -1376,11 +1377,12 @@ Box.prototype.render = function(stop) {
// TODO: Check for 'center', recalculate yi, and xi. Better // TODO: Check for 'center', recalculate yi, and xi. Better
// yet, simply move this check into this.left/width/etc. // yet, simply move this check into this.left/width/etc.
if (this.shrink) { if (this.shrink) {
var hw = this._getShrinkSize(content) hw = this._getShrinkSize(content);
, h = hw.height h = hw.height;
, w = hw.width w = hw.width;
, xll = xl xll = xl;
, yll = yl; yll = yl;
if (this.options.width == null if (this.options.width == null
&& (this.options.left == null && (this.options.left == null
|| this.options.right == null)) { || this.options.right == null)) {
@ -1392,6 +1394,7 @@ Box.prototype.render = function(stop) {
//xl++; // make it one cell wider for newlines //xl++; // make it one cell wider for newlines
} }
} }
if (this.options.height == null if (this.options.height == null
&& (this.options.top == null && (this.options.top == null
|| this.options.bottom == null) || this.options.bottom == null)
@ -1402,12 +1405,14 @@ Box.prototype.render = function(stop) {
yl = yi_ + h + (this.border ? 2 : 0) + this.padding; yl = yi_ + h + (this.border ? 2 : 0) + this.padding;
} }
} }
// Recenter shrunken elements. // Recenter shrunken elements.
if (xl < xll && this.options.left === 'center') { if (xl < xll && this.options.left === 'center') {
xll = (xll - xl) / 2 | 0; xll = (xll - xl) / 2 | 0;
xi_ += xll; xi_ += xll;
xl += xll; xl += xll;
} }
if (yl < yll && this.options.top === 'center') { if (yl < yll && this.options.top === 'center') {
yll = (yll - yl) / 2 | 0; yll = (yll - yl) / 2 | 0;
yi_ += yll; yi_ += yll;
@ -1415,7 +1420,7 @@ Box.prototype.render = function(stop) {
} }
} }
var ret = this._lastPos = { ret = this._lastPos = {
xi: xi_, xi: xi_,
xl: xl, xl: xl,
yi: yi_, yi: yi_,
@ -1433,7 +1438,7 @@ Box.prototype.render = function(stop) {
// Check previous line for escape codes. // Check previous line for escape codes.
if (this.contentIndex != null && this.childBase > 0 && this._clines) { if (this.contentIndex != null && this.childBase > 0 && this._clines) {
var cci = ci - (this._clines[this.childBase - 1].length + 1); cci = ci - (this._clines[this.childBase - 1].length + 1);
for (; cci < ci; cci++) { for (; cci < ci; cci++) {
if (content[cci] === '\x1b') { if (content[cci] === '\x1b') {
if (c = /^\x1b\[[\d;]*m/.exec(content.substring(cci))) { if (c = /^\x1b\[[\d;]*m/.exec(content.substring(cci))) {
@ -1509,6 +1514,7 @@ outer:
h = this.items ? this.items.length : this._clines.length; h = this.items ? this.items.length : this._clines.length;
if (this.scrollbar && (yl - yi_) < h) { if (this.scrollbar && (yl - yi_) < h) {
xi = xl - 1; xi = xl - 1;
if (this.scrollbar.ignoreBorder && this.border) xi++;
yi = h - (yl - yi_) - (this.border ? 2 : 0); yi = h - (yl - yi_) - (this.border ? 2 : 0);
yi = yi_ + (((yl - yi_) * (this.childBase / yi)) | 0); yi = yi_ + (((yl - yi_) * (this.childBase / yi)) | 0);
cell = lines[yi] && lines[yi][xi]; cell = lines[yi] && lines[yi][xi];