cleaner content parsing.
This commit is contained in:
parent
38c9f1f177
commit
5265275d0d
|
@ -826,22 +826,6 @@ Element.prototype.emit = function(type) {
|
|||
};
|
||||
*/
|
||||
|
||||
Element.prototype.parseContent = function() {
|
||||
if (this.detached) return false;
|
||||
|
||||
var w = this.width - (this.border ? 2 : 0);
|
||||
if (this._clines == null
|
||||
|| this._clines.width !== w
|
||||
|| this._clines.content !== this.content) {
|
||||
this._clines = wrapContent(this.content, w, this.parseTags, this.align);
|
||||
this._pcontent = this._clines.join('\n');
|
||||
this.emit('parsed content');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
Element.prototype.hide = function() {
|
||||
if (this.hidden) return;
|
||||
this.hidden = true;
|
||||
|
@ -880,18 +864,36 @@ Element.prototype.focus = function() {
|
|||
};
|
||||
|
||||
Element.prototype.setContent = function(content, noClear) {
|
||||
//var ret = this.render(true);
|
||||
var ret = this._lastPos;
|
||||
// TODO: Maybe simply set _pcontent with _parseTags result.
|
||||
// text = text.replace(/\x1b(?!\[[\d;]*m)/g, '');
|
||||
this.content = this._parseTags(content || '');
|
||||
this.content = content || '';
|
||||
this.parseContent();
|
||||
if (ret && !noClear) {
|
||||
//if (ret && !this.hidden) {
|
||||
this.screen.clearRegion(ret.xi, ret.xl, ret.yi, ret.yl);
|
||||
}
|
||||
};
|
||||
|
||||
Element.prototype.parseContent = function() {
|
||||
if (this.detached) return false;
|
||||
|
||||
var width = this.width - (this.border ? 2 : 0);
|
||||
if (this._clines == null
|
||||
|| this._clines.width !== width
|
||||
|| this._clines.content !== this.content) {
|
||||
var content = this.content;
|
||||
// Could move these 2 lines back to setContent (?)
|
||||
content = content.replace(/\x1b(?!\[[\d;]*m)/g, '');
|
||||
content = this._parseTags(content || '');
|
||||
this._clines = wrapContent(content, width, this.parseTags, this.align);
|
||||
this._clines.width = width;
|
||||
this._clines.content = this.content;
|
||||
this._pcontent = this._clines.join('\n');
|
||||
this.emit('parsed content');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// Convert `{red-fg}foo{/red-fg}` to `\x1b[31mfoo\x1b[39m`.
|
||||
Element.prototype._parseTags = function(text) {
|
||||
if (!this.parseTags) return text;
|
||||
|
@ -2477,9 +2479,6 @@ function wrapContent(content, width, tags, state) {
|
|||
out.push(sp(line, width, align));
|
||||
});
|
||||
|
||||
out.width = width;
|
||||
out.content = content;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue