fix textarea for full unicode.

This commit is contained in:
Christopher Jeffrey 2015-04-16 16:16:55 -07:00
parent 5dacfbad97
commit 7b31f45468
3 changed files with 16 additions and 5 deletions

View File

@ -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,8 +5878,17 @@ Textarea.prototype._listener = function(ch, key) {
done(null, null);
} else if (key.name === 'backspace') {
if (this.value.length) {
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)) {
this.value += ch;

View File

@ -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);

View File

@ -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({