From ced4324c3f8b5204bbc31057c496dff6ab52a83d Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 3 Dec 2018 13:08:14 +0100 Subject: [PATCH 1/2] Revert "repl: handle buffered string logic on finish" This reverts commit eb42c1eb4f2502433a22c49ede9e657fb6cd86e0. --- lib/readline.js | 6 +++--- lib/repl.js | 8 +------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index e55507416b0b08..8d03cd6e332d91 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -357,9 +357,9 @@ Interface.prototype.undoHistory = function() { // If it's a multiline code, then add history // accordingly. -Interface.prototype.multilineHistory = function(clearBuffer) { - // if not clear buffer, add multiline history - if (!clearBuffer && this.terminal) { +Interface.prototype.multilineHistory = function() { + // check if we got a multiline code + if (this.multiline !== '' && this.terminal) { const dupIndex = this.history.indexOf(this.multiline); if (dupIndex !== -1) this.history.splice(dupIndex, 1); // Remove the last entered line as multiline diff --git a/lib/repl.js b/lib/repl.js index 1ab4031f09cb9a..bb5ea3d9500a89 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -666,13 +666,6 @@ function REPLServer(prompt, } } - // handle multiline history - if (self[kBufferedCommandSymbol].length) - Interface.prototype.multilineHistory.call(self, false); - else { - Interface.prototype.multilineHistory.call(self, true); - } - // Clear buffer if no SyntaxErrors self.clearBufferedCommand(); sawCtrlD = false; @@ -781,6 +774,7 @@ exports.start = function(prompt, REPLServer.prototype.clearBufferedCommand = function clearBufferedCommand() { this[kBufferedCommandSymbol] = ''; + REPLServer.super_.prototype.multilineHistory.call(this); }; REPLServer.prototype.close = function close() { From 1a33e1435e5c36b3e251772c15d12ca37cf0e6d4 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 3 Dec 2018 13:10:15 +0100 Subject: [PATCH 2/2] Revert "lib: repl multiline history support" This reverts commit dd7a3d246ded89cd0c910231c9adec279e72f9a9. --- lib/readline.js | 25 ------------------- lib/repl.js | 2 -- test/parallel/test-repl-persistent-history.js | 7 ------ 3 files changed, 34 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index 8d03cd6e332d91..5d47c51b993bbe 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -225,7 +225,6 @@ function Interface(input, output, completer, terminal) { // Current line this.line = ''; - this.multiline = ''; this._setRawMode(true); this.terminal = true; @@ -337,7 +336,6 @@ Interface.prototype._addHistory = function() { if (dupIndex !== -1) this.history.splice(dupIndex, 1); } - this.multiline += this.line; this.history.unshift(this.line); // Only store so many @@ -348,29 +346,6 @@ Interface.prototype._addHistory = function() { return this.history[0]; }; -// Called when a multiline is seen by the repl -Interface.prototype.undoHistory = function() { - if (this.terminal) { - this.history.shift(); - } -}; - -// If it's a multiline code, then add history -// accordingly. -Interface.prototype.multilineHistory = function() { - // check if we got a multiline code - if (this.multiline !== '' && this.terminal) { - const dupIndex = this.history.indexOf(this.multiline); - if (dupIndex !== -1) this.history.splice(dupIndex, 1); - // Remove the last entered line as multiline - // already contains them. - this.history.shift(); - this.history.unshift(this.multiline); - } - - // clear the multiline buffer - this.multiline = ''; -}; Interface.prototype._refreshLine = function() { // line length diff --git a/lib/repl.js b/lib/repl.js index bb5ea3d9500a89..dd675fc435dcd8 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -774,7 +774,6 @@ exports.start = function(prompt, REPLServer.prototype.clearBufferedCommand = function clearBufferedCommand() { this[kBufferedCommandSymbol] = ''; - REPLServer.super_.prototype.multilineHistory.call(this); }; REPLServer.prototype.close = function close() { @@ -889,7 +888,6 @@ REPLServer.prototype.displayPrompt = function(preserveCursor) { const len = this.lines.level.length ? this.lines.level.length - 1 : 0; const levelInd = '..'.repeat(len); prompt += levelInd + ' '; - Interface.prototype.undoHistory.call(this); } // Do not overwrite `_initialPrompt` here diff --git a/test/parallel/test-repl-persistent-history.js b/test/parallel/test-repl-persistent-history.js index 32bab3c8ed9f83..bb10085eccfcf6 100644 --- a/test/parallel/test-repl-persistent-history.js +++ b/test/parallel/test-repl-persistent-history.js @@ -111,13 +111,6 @@ const tests = [ test: [UP], expected: [prompt, replFailedRead, prompt, replDisabled, prompt] }, - { // Tests multiline history - env: {}, - test: ['{', '}', UP, CLEAR], - expected: [prompt, '{', '... ', '}', '{}\n', - prompt, `${prompt}{}`, prompt], - clean: false - }, { before: function before() { if (common.isWindows) {