diff --git a/lib/readline.js b/lib/readline.js index ecbeed544f5..d5740942002 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -720,7 +720,7 @@ Interface.prototype._historyPrev = function() { Interface.prototype._getDisplayPos = function(str) { let offset = 0; const col = this.columns; - let row = 0; + let rows = 0; str = stripVTControlCharacters(str); for (let i = 0, len = str.length; i < len; i++) { const code = str.codePointAt(i); @@ -728,8 +728,8 @@ Interface.prototype._getDisplayPos = function(str) { i++; } if (code === 0x0a) { // new line \n - // row must be incremented by 1 even if offset = 0 or col = +Infinity - row += MathCeil(offset / col) || 1; + // rows must be incremented by 1 even if offset = 0 or col = +Infinity + rows += MathCeil(offset / col) || 1; offset = 0; continue; } @@ -744,8 +744,8 @@ Interface.prototype._getDisplayPos = function(str) { } } const cols = offset % col; - const rows = row + (offset - cols) / col; - return { cols: cols, rows: rows }; + rows += (offset - cols) / col; + return { cols, rows }; }; @@ -753,8 +753,7 @@ Interface.prototype._getDisplayPos = function(str) { Interface.prototype.getCursorPos = function() { const columns = this.columns; const strBeforeCursor = this._prompt + this.line.substring(0, this.cursor); - const dispPos = this._getDisplayPos( - stripVTControlCharacters(strBeforeCursor)); + const dispPos = this._getDisplayPos(strBeforeCursor); let cols = dispPos.cols; let rows = dispPos.rows; // If the cursor is on a full-width character which steps over the line, @@ -765,7 +764,7 @@ Interface.prototype.getCursorPos = function() { rows++; cols = 0; } - return { cols: cols, rows: rows }; + return { cols, rows }; }; Interface.prototype._getCursorPos = Interface.prototype.getCursorPos;