Skip to content

Commit

Permalink
fixup: don't early assign the value
Browse files Browse the repository at this point in the history
  • Loading branch information
apapirovski committed Feb 4, 2018
1 parent eda075e commit 81ce2d1
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,9 @@ Interface.prototype._normalWrite = function(b) {
if (b === undefined) {
return;
}
const now = Date.now();
var string = this._decoder.write(b);
if (this._sawReturnAt &&
now - this._sawReturnAt <= this.crlfDelay) {
Date.now() - this._sawReturnAt <= this.crlfDelay) {
string = string.replace(/^\n/, '');
this._sawReturnAt = 0;
}
Expand All @@ -423,7 +422,7 @@ Interface.prototype._normalWrite = function(b) {
this._line_buffer = null;
}
if (newPartContainsEnding) {
this._sawReturnAt = string.endsWith('\r') ? now : 0;
this._sawReturnAt = string.endsWith('\r') ? Date.now() : 0;

// got one or more newlines; process into "line" events
var lines = string.split(lineEnding);
Expand Down Expand Up @@ -910,22 +909,20 @@ Interface.prototype._ttyWrite = function(s, key) {
} else {
/* No modifier keys used */

const now = Date.now();

// \r bookkeeping is only relevant if a \n comes right after.
if (this._sawReturnAt && key.name !== 'enter')
this._sawReturnAt = 0;

switch (key.name) {
case 'return': // carriage return, i.e. \r
this._sawReturnAt = now;
this._sawReturnAt = Date.now();
this._line();
break;

case 'enter':
// When key interval > crlfDelay
if (this._sawReturnAt === 0 ||
now - this._sawReturnAt > this.crlfDelay) {
Date.now() - this._sawReturnAt > this.crlfDelay) {
this._line();
}
this._sawReturnAt = 0;
Expand Down

0 comments on commit 81ce2d1

Please sign in to comment.