Skip to content

Commit bd8be40

Browse files
antsmartianrvagg
authored andcommitted
repl: handle buffered string logic on finish
Looks like `clearBufferedCommand` will be called on almost all flows. Hence history was broken. PR-URL: #24389 Fixes: #24385 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 21e9aa2 commit bd8be40

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/readline.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ Interface.prototype.undoHistory = function() {
348348

349349
// If it's a multiline code, then add history
350350
// accordingly.
351-
Interface.prototype.multilineHistory = function() {
352-
// check if we got a multiline code
353-
if (this.multiline !== '' && this.terminal) {
351+
Interface.prototype.multilineHistory = function(clearBuffer) {
352+
// if not clear buffer, add multiline history
353+
if (!clearBuffer && this.terminal) {
354354
const dupIndex = this.history.indexOf(this.multiline);
355355
if (dupIndex !== -1) this.history.splice(dupIndex, 1);
356356
// Remove the last entered line as multiline

lib/repl.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,13 @@ function REPLServer(prompt,
668668
}
669669
}
670670

671+
// handle multiline history
672+
if (self[kBufferedCommandSymbol].length)
673+
REPLServer.super_.prototype.multilineHistory.call(self, false);
674+
else {
675+
REPLServer.super_.prototype.multilineHistory.call(self, true);
676+
}
677+
671678
// Clear buffer if no SyntaxErrors
672679
self.clearBufferedCommand();
673680
sawCtrlD = false;
@@ -774,7 +781,6 @@ exports.start = function(prompt,
774781

775782
REPLServer.prototype.clearBufferedCommand = function clearBufferedCommand() {
776783
this[kBufferedCommandSymbol] = '';
777-
REPLServer.super_.prototype.multilineHistory.call(this);
778784
};
779785

780786
REPLServer.prototype.close = function close() {

0 commit comments

Comments
 (0)