From ba4108445ae9ed18cad481b987d907ebf3c323b0 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 1 May 2015 17:44:49 -0700 Subject: [PATCH] avoid wrapping shortfall due to surrogate pairs. --- lib/widget.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/widget.js b/lib/widget.js index e70cc79..c44dc17 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -2846,6 +2846,17 @@ main: } else { // Try to find a character to break on. if (i !== line.length) { + // + // Compensate for surrogate length + // counts on wrapping (experimental): + // NOTE: Could optimize this by putting + // it in the parent for loop. + if (unicode.isSurrogate(line, i)) i--; + for (var s = 0, n = 0; n < i; n++) { + if (unicode.isSurrogate(line, n)) s++, n++; + } + i += s; + // j = i; // Break _past_ space. // Break _past_ double-width chars.