do not break on spaces, double-widths, surrogates, or combinings for text wrapping.

This commit is contained in:
Christopher Jeffrey 2015-04-26 06:32:02 -07:00
parent 9a2b6dfd81
commit 2eb57cc725

View File

@ -2424,7 +2424,7 @@ Element.prototype.parseContent = function(noTags) {
if (this.screen.fullUnicode) {
// double-width chars will eat the next char after render. create a
// blank character after it so it doesn't eat the real next char.
content = content.replace(unicode.chars.wide, '$1 ');
content = content.replace(unicode.chars.wide, '$1\x03');
} else {
// no double-width: replace them with question-marks.
content = content.replace(unicode.chars.all, '??');
@ -2712,11 +2712,37 @@ main:
rtof.push(no);
continue main;
}
// Try to find a space to break on.
if (i !== line.length) {
j = i;
while (j > i - 10 && j > 0 && line[--j] !== ' ');
if (line[j] === ' ') i = j + 1;
if (!this.screen.fullUnicode) {
// Try to find a space to break on.
if (i !== line.length) {
j = i;
while (j > i - 10 && j > 0 && line[--j] !== ' ');
if (line[j] === ' ') i = j + 1;
}
} else {
// Try to find a character to break on.
if (i !== line.length) {
j = i;
// Break _past_ space.
// Break _past_ double-width chars.
// Break _past_ surrogate pairs.
// Break _past_ combining chars.
while (j > i - 10 && j > 0) {
j--;
if (line[j] === ' '
|| line[j] === '\x03'
|| unicode.isSurrogate(line, j - 1)
|| unicode.combining[line[j]]) {
break;
}
}
if (line[j] === ' '
|| line[j] === '\x03'
|| unicode.isSurrogate(line, j - 1)
|| unicode.combining[line[j]]) {
i = j + 1;
}
}
}
break;
}