diff --git a/lib/readline.js b/lib/readline.js index e6b57927791..0161b4e292e 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -188,12 +188,14 @@ Interface.prototype._onLine = function(line) { Interface.prototype._addHistory = function() { if (this.line.length === 0) return ''; - this.history.unshift(this.line); + if (this.history.length === 0 || this.history[0] !== this.line) { + this.history.unshift(this.line); + + // Only store so many + if (this.history.length > kHistorySize) this.history.pop(); + } + this.historyIndex = -1; - - // Only store so many - if (this.history.length > kHistorySize) this.history.pop(); - return this.history[0]; };