From 46e9c52030a6bc1c40cdeb31c3599fe71ec1ebe6 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 27 Apr 2015 15:03:04 -0700 Subject: [PATCH] cursor position in textarea. --- lib/widget.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/widget.js b/lib/widget.js index fc7506b..1b16c6a 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -5901,7 +5901,7 @@ Textarea.prototype._updateCursor = function(get) { line = Math.max(0, line); cy = lpos.yi + this.itop + line; - cx = lpos.xi + this.ileft + last.length; + cx = lpos.xi + this.ileft + this._strWidth(last); // XXX Not sure, but this may still sometimes // cause problems when leaving editor. @@ -5926,6 +5926,12 @@ Textarea.prototype._updateCursor = function(get) { } }; +Textarea.prototype._strWidth = function(str) { + if (!this.screen.fullUnicode) return str.length; + str = str.replace(/\x03/g, ''); + return unicode.strWidth(str, 0); +}; + Textarea.prototype.input = Textarea.prototype.setInput = Textarea.prototype.readInput = function(callback) { @@ -6033,6 +6039,7 @@ Textarea.prototype._listener = function(ch, key) { if (this.value.length) { if (this.screen.fullUnicode) { if (unicode.isSurrogate(this.value, this.value.length - 2)) { + // || unicode.isCombining(this.value, this.value.length - 1)) { this.value = this.value.slice(0, -2); } else { this.value = this.value.slice(0, -1);