diff --git a/lib/widget.js b/lib/widget.js index 6549618..4659aae 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -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; }