diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-12-17 20:01:09 +0300 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-12-25 13:17:31 +0300 |
commit | b768e84794604b2a7d7e004e6fe838145b80098c (patch) | |
tree | 82a27527c84e985291144197c83bcf681071d99e /lib | |
parent | 9e4349e7972b35c23235dde0f5053f0244abaf0a (diff) |
readline: small refactoring
This just removes some redundant work and some other small things.
PR-URL: https://github.com/nodejs/node/pull/31006
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/readline.js | 15 |
1 files changed, 7 insertions, 8 deletions
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; |