From 7b31f45468f2e9a7f10e1df034246a6993392eee Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 16 Apr 2015 16:16:55 -0700 Subject: [PATCH] fix textarea for full unicode. --- lib/widget.js | 17 +++++++++++++---- test/widget-eaw.js | 1 + test/widget-textarea.js | 3 ++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 5eba50e..4d2e0b8 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -1215,15 +1215,15 @@ Screen.prototype.draw = function(start, end) { // 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] = ' '; + 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] = ' '; + o[x][1] = '\0'; // Eat the next character by moving forward and marking as a // space (which it is). - o[++x][1] = ' '; + o[++x][1] = '\0'; } } } @@ -5878,7 +5878,16 @@ Textarea.prototype._listener = function(ch, key) { done(null, null); } else if (key.name === 'backspace') { if (this.value.length) { - this.value = this.value.slice(0, -1); + if (this.screen.fullUnicode) { + if (this.value[this.value.length - 2] + && unicode.isSurrogate(this.value[this.value.length - 2])) { + this.value = this.value.slice(0, -2); + } else { + this.value = this.value.slice(0, -1); + } + } else { + this.value = this.value.slice(0, -1); + } } } else if (ch) { if (!/^[\x00-\x08\x0b-\x0c\x0e-\x1f\x7f]$/.test(ch)) { diff --git a/test/widget-eaw.js b/test/widget-eaw.js index 988bb47..7434cdd 100644 --- a/test/widget-eaw.js +++ b/test/widget-eaw.js @@ -17,6 +17,7 @@ screen = blessed.screen({ // screen.tput.strings.enter_alt_charset_mode = false; // var DOUBLE = '杜'; +// '杜' var DOUBLE = String.fromCodePoint ? String.fromCodePoint(0x675c) : String.fromCharCode(0x675c); diff --git a/test/widget-textarea.js b/test/widget-textarea.js index c98f964..8ba609f 100644 --- a/test/widget-textarea.js +++ b/test/widget-textarea.js @@ -2,7 +2,8 @@ var blessed = require('../') , screen; screen = blessed.screen({ - dump: __dirname + '/logs/textarea.log' + dump: __dirname + '/logs/textarea.log', + fullUnicode: true }); var box = blessed.textarea({