optimize shrink width.

This commit is contained in:
Christopher Jeffrey 2013-07-28 09:58:42 -05:00
parent 9cc1f53d9a
commit f236898f73
1 changed files with 9 additions and 20 deletions

View File

@ -1979,8 +1979,7 @@ Element.prototype._align = function(line, width, align) {
}; };
Element.prototype._wrapContent = function(content, width) { Element.prototype._wrapContent = function(content, width) {
var self = this var tags = this.parseTags
, tags = this.parseTags
, state = this.align , state = this.align
, wrap = this.wrap , wrap = this.wrap
, margin = 0 , margin = 0
@ -1989,6 +1988,7 @@ Element.prototype._wrapContent = function(content, width) {
, fake = [] , fake = []
, out = [] , out = []
, no = 0 , no = 0
, mwidth = 0
, line , line
, align , align
, cap , cap
@ -2064,9 +2064,10 @@ main:
part = line.substring(0, i); part = line.substring(0, i);
line = line.substring(i); line = line.substring(i);
out.push(self._align(part, width, align)); out.push(this._align(part, width, align));
ftor[no].push(out.length - 1); ftor[no].push(out.length - 1);
rtof.push(no); rtof.push(no);
if (part.length > mwidth) mwidth = part.length;
// Make sure we didn't wrap the line to the very end, otherwise // Make sure we didn't wrap the line to the very end, otherwise
// we get a pointless empty line after a newline. // we get a pointless empty line after a newline.
@ -2079,15 +2080,17 @@ main:
} }
} }
out.push(self._align(line, width, align)); out.push(this._align(line, width, align));
ftor[no].push(out.length - 1); ftor[no].push(out.length - 1);
rtof.push(no); rtof.push(no);
if (line.length > mwidth) mwidth = line.length;
} }
out.rtof = rtof; out.rtof = rtof;
out.ftor = ftor; out.ftor = ftor;
out.fake = lines; out.fake = lines;
out.real = out; out.real = out;
out.mwidth = mwidth;
return out; return out;
}; };
@ -2486,19 +2489,6 @@ Element.prototype.__defineGetter__('tpadding', function() {
* Rendering - here be dragons * Rendering - here be dragons
*/ */
Element.prototype._getShrinkSize = function() {
// TODO: Possibly move this to parseContent.
return {
height: this._clines.length,
width: this._clines.reduce(function(current, line) {
line = line.replace(/\x1b\[[\d;]*m/g, '');
return line.length > current
? line.length
: current;
}, 0)
};
};
Element.prototype._getShrinkBox = function(xi, xl, yi, yl) { Element.prototype._getShrinkBox = function(xi, xl, yi, yl) {
if (!this.children.length) { if (!this.children.length) {
return { xi: xi, xl: xi, yi: yi, yl: yi }; return { xi: xi, xl: xi, yi: yi, yl: yi };
@ -2547,9 +2537,8 @@ Element.prototype._getShrinkBox = function(xi, xl, yi, yl) {
}; };
Element.prototype._getShrinkContent = function(xi, xl, yi, yl) { Element.prototype._getShrinkContent = function(xi, xl, yi, yl) {
var hw = this._getShrinkSize() var h = this._clines.length
, h = hw.height , w = this._clines.mwidth;
, w = hw.width;
if (this.position.width == null if (this.position.width == null
&& (this.position.left == null && (this.position.left == null