diff --git a/lib/widget.js b/lib/widget.js index 38e4690..ac68b28 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -1209,25 +1209,23 @@ Screen.prototype.draw = function(start, end) { // If this is a surrogate pair double-width char, we can ignore it // because parseContent already counted it as length=2. point = unicode.codePointAt(line[x][1], 0); - if (point <= 0x00ffff) { - cwid = unicode.charWidth(point); - if (cwid === 2) { - // Might also need: `line[x + 1][0] !== line[x][0]` - // for borderless boxes? - if (x === line.length - 1 || angles[line[x + 1][1]]) { - // If we're at the end, we don't have enough space for a - // double-width. Overwrite it with a space and ignore. - ch = ' '; - o[x][1] = '\0'; - } else { - // ALWAYS refresh double-width chars because this special cursor - // behavior is needed. There may be a more efficient way of doing - // this. See above. - o[x][1] = '\0'; - // Eat the next character by moving forward and marking as a - // space (which it is). - o[++x][1] = '\0'; - } + cwid = unicode.charWidth(point); + if (cwid === 2) { + // Might also need: `line[x + 1][0] !== line[x][0]` + // for borderless boxes? + if (x === line.length - 1 || angles[line[x + 1][1]]) { + // If we're at the end, we don't have enough space for a + // double-width. Overwrite it with a space and ignore. + ch = ' '; + o[x][1] = '\0'; + } else { + // ALWAYS refresh double-width chars because this special cursor + // behavior is needed. There may be a more efficient way of doing + // this. See above. + o[x][1] = '\0'; + // Eat the next character by moving forward and marking as a + // space (which it is). + o[++x][1] = '\0'; } } } @@ -2079,14 +2077,12 @@ Screen.prototype.screenshot = function(xi, xl, yi, yl, term) { if (this.fullUnicode) { point = unicode.codePointAt(line[x][1], 0); - if (point <= 0x00ffff) { - cwid = unicode.charWidth(point); - if (cwid === 2) { - if (x === xl - 1) { - ch = ' '; - } else { - x++; - } + cwid = unicode.charWidth(point); + if (cwid === 2) { + if (x === xl - 1) { + ch = ' '; + } else { + x++; } } } @@ -2432,12 +2428,9 @@ 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\x03'); + content = content.replace(unicode.chars.all, '$1\x03'); // VTE cannot display double-width chars that are also // surrogate pairs: It miscalculates the width of the chars. - if (this.screen.program.isVTE) { - content = content.replace(unicode.chars.swide, '??'); - } } else { // no double-width: replace them with question-marks. content = content.replace(unicode.chars.all, '??'); @@ -2744,14 +2737,14 @@ main: j--; if (line[j] === ' ' || line[j] === '\x03' - || unicode.isSurrogate(line, j - 1) + || (unicode.isSurrogate(line, j - 1) && line[j + 1] !== '\x03') || unicode.combining[line[j]]) { break; } } if (line[j] === ' ' || line[j] === '\x03' - || unicode.isSurrogate(line, j - 1) + || (unicode.isSurrogate(line, j - 1) && line[j + 1] !== '\x03') || unicode.combining[line[j]]) { i = j + 1; } @@ -2796,31 +2789,6 @@ main: : current; }, 0); - // Find all surrogate pairs and compensate for the lack of width - // on the line by padding with trailing spaces: - if (this.screen.fullUnicode) { - for (var i = 0; i < out.length; i++) { - // NOTE: Happens at 54 cols with all chars enabled in test. - // Check to see if surrogates got split on end and beginning of 2 lines. - if (/[\ud800-\udbff]$/.exec(out[i]) - && /^[\udc00-\udfff]/.exec(out[i + 1])) { - out[i] = out[i] + out[i + 1][0]; - out[i + 1] = out[i + 1].substring(1) + ' '; - } - // Pad the end of the lines if the surrogate is not a double-width char. - // var surrogates = out[i].length - punycode.ucs2.decode(out[i]).length; - var surrogates = out[i].match(unicode.chars.surrogate); - if (surrogates && surrogates.length) { - for (var j = 0; j < surrogates.length; j++) { - var cwid = unicode.charWidth(surrogates[j], 0); - if (cwid === 1) { - out[i] += ' '; - } - } - } - } - } - return out; }; diff --git a/test/widget-eaw.js b/test/widget-eaw.js index a16f2ae..854bd1d 100644 --- a/test/widget-eaw.js +++ b/test/widget-eaw.js @@ -22,11 +22,15 @@ var DOUBLE = DU + JUAN; // var SURROGATE_DOUBLE = '𰀀'; // var SURROGATE_DOUBLE = String.fromCharCode(0xD880, 0xDC00); -var SURROGATE_DOUBLE = unicode.fromCodePoint(0x30000); +// var SURROGATE_DOUBLE = unicode.fromCodePoint(0x30000); -// var SURROGATE_DOUBLE_OTHER = '🉐'; -// var SURROGATE_DOUBLE_OTHER = String.fromCharCode(0xD83C, 0xDE50); -var SURROGATE_DOUBLE_OTHER = unicode.fromCodePoint(0x1F250); +// var SURROGATE_DOUBLE = '𠀀'; +// var SURROGATE_DOUBLE = String.fromCharCode(0xd840, 0xdc00); +var SURROGATE_DOUBLE = unicode.fromCodePoint(0x20000); + +// var SURROGATE_DOUBLE = '🉐'; +// var SURROGATE_DOUBLE = String.fromCharCode(0xD83C, 0xDE50); +// var SURROGATE_DOUBLE = unicode.fromCodePoint(0x1F250); // var SURROGATE_SINGLE = '𝌆'; // var SURROGATE_SINGLE = String.fromCharCode(0xD834, 0xDF06);