Skip to content

Commit 92dcf3e

Browse files
committed
readline: small refactoring
This just removes some redundant work and some other small things. PR-URL: #31006 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 09ca8be commit 92dcf3e

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

‎lib/readline.js‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -720,16 +720,16 @@ Interface.prototype._historyPrev = function() {
720720
Interface.prototype._getDisplayPos=function(str){
721721
letoffset=0;
722722
constcol=this.columns;
723-
letrow=0;
723+
letrows=0;
724724
str=stripVTControlCharacters(str);
725725
for(leti=0,len=str.length;i<len;i++){
726726
constcode=str.codePointAt(i);
727727
if(code>=kUTF16SurrogateThreshold){// Surrogates.
728728
i++;
729729
}
730730
if(code===0x0a){// new line \n
731-
// row must be incremented by 1 even if offset = 0 or col = +Infinity
732-
row+=MathCeil(offset/col)||1;
731+
// rows must be incremented by 1 even if offset = 0 or col = +Infinity
732+
rows+=MathCeil(offset/col)||1;
733733
offset=0;
734734
continue;
735735
}
@@ -744,17 +744,16 @@ Interface.prototype._getDisplayPos = function(str) {
744744
}
745745
}
746746
constcols=offset%col;
747-
constrows=row+(offset-cols)/col;
748-
return{cols: cols,rows:rows};
747+
rows+=(offset-cols)/col;
748+
return{ cols, rows };
749749
};
750750

751751

752752
// Returns current cursor's position and line
753753
Interface.prototype.getCursorPos=function(){
754754
constcolumns=this.columns;
755755
conststrBeforeCursor=this._prompt+this.line.substring(0,this.cursor);
756-
constdispPos=this._getDisplayPos(
757-
stripVTControlCharacters(strBeforeCursor));
756+
constdispPos=this._getDisplayPos(strBeforeCursor);
758757
letcols=dispPos.cols;
759758
letrows=dispPos.rows;
760759
// If the cursor is on a full-width character which steps over the line,
@@ -765,7 +764,7 @@ Interface.prototype.getCursorPos = function() {
765764
rows++;
766765
cols=0;
767766
}
768-
return{cols: cols,rows:rows};
767+
return{ cols, rows };
769768
};
770769
Interface.prototype._getCursorPos=Interface.prototype.getCursorPos;
771770

0 commit comments

Comments
 (0)