0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

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>
This commit is contained in:
Ruben Bridgewater 2019-12-17 18:01:09 +01:00
parent 9e4349e797
commit b768e84794
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

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