textLength improvement.
This commit is contained in:
parent
7a3525be77
commit
51c3d88a69
|
@ -487,6 +487,7 @@ parameter must be a string.
|
|||
- __getLines()__ - an array containing the content lines.
|
||||
- __getScreenLines()__ - an array containing the lines as they are displayed on
|
||||
the screen.
|
||||
- __textLength(text)__ - get a string's real length, taking into account tags.
|
||||
|
||||
|
||||
#### Box (from Element)
|
||||
|
|
|
@ -2307,7 +2307,10 @@ Element.prototype.textLength = function(text) {
|
|||
if (!this.options.tags && !this.options.parseTags) {
|
||||
return text.length;
|
||||
}
|
||||
return text.replace(/{(\/?)([\w\-,;!#]*)}/g, '').length;
|
||||
return text
|
||||
.replace(/{(\/?)([\w\-,;!#]*)}/g, '')
|
||||
.replace(/\x1b\[[\d;]*m/g, '')
|
||||
.length;
|
||||
};
|
||||
|
||||
// Convert `{red-fg}foo{/red-fg}` to `\x1b[31mfoo\x1b[39m`.
|
||||
|
|
Loading…
Reference in New Issue