From 47dfa22adb83b576ec8dceeb7b8c84f10c2d3ea5 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 11 Dec 2019 19:37:44 +0100 Subject: [PATCH] repl: fix preview bug in case of long lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This addresses an issue that is caused by lines that exceed the current window columns. That would cause the preview to confuse the REPL. This is meant as hot fix. The preview should be able to handle these cases appropriately as well later on. PR-URL: https://github.com/nodejs/node/pull/30907 Reviewed-By: Michaƫl Zasso Reviewed-By: Rich Trott --- lib/internal/repl/utils.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/internal/repl/utils.js b/lib/internal/repl/utils.js index bdc402ee08715d..c54e173bdf3e1c 100644 --- a/lib/internal/repl/utils.js +++ b/lib/internal/repl/utils.js @@ -280,6 +280,16 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { return; } + // Do not show previews in case the current line is longer than the column + // width. + // TODO(BridgeAR): Fix me. This should not be necessary. It currently breaks + // the output though. We also have to check for characters that have more + // than a single byte as length. Check Interface.prototype._moveCursor. It + // contains the necessary logic. + if (repl.line.length + repl._prompt.length > repl.columns) { + return; + } + // Add the autocompletion preview. // TODO(BridgeAR): Trigger the input preview after the completion preview. // That way it's possible to trigger the input prefix including the