From 3ea0397a1a679e7ffaaf353bc67afca2a4065fa5 Mon Sep 17 00:00:00 2001 From: Vladimir Beloborodov Date: Wed, 13 Jun 2012 21:37:31 +0400 Subject: [PATCH] readline: Use one history item for reentered line If the command entered is exactly the same as the last history item, don't dupe it in the history --- lib/readline.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index e6b5792779..0161b4e292 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); - this.historyIndex = -1; + 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(); + // Only store so many + if (this.history.length > kHistorySize) this.history.pop(); + } + this.historyIndex = -1; return this.history[0]; };