From cdc867a39168166f5cc85a64271cfecff6195938 Mon Sep 17 00:00:00 2001 From: RobO Date: Tue, 8 Mar 2022 19:51:46 -0500 Subject: [PATCH] fix input of "rawlist" (#1089) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rob O’Connor Co-authored-by: Simon Boudrias --- packages/inquirer/lib/prompts/rawlist.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/inquirer/lib/prompts/rawlist.js b/packages/inquirer/lib/prompts/rawlist.js index 243fa8c64..d09337a2a 100644 --- a/packages/inquirer/lib/prompts/rawlist.js +++ b/packages/inquirer/lib/prompts/rawlist.js @@ -15,6 +15,9 @@ class RawListPrompt extends Base { constructor(questions, rl, answers) { super(questions, rl, answers); + this.hiddenLine = ''; + this.lastKey = ''; + if (!this.opt.choices) { this.throwParamError('choices'); } @@ -145,7 +148,14 @@ class RawListPrompt extends Base { */ onKeypress() { - const index = this.rl.line.length ? Number(this.rl.line) - 1 : 0; + let index; + + if (this.lastKey === 'arrow') { + index = this.hiddenLine.length ? Number(this.hiddenLine) - 1 : 0; + } else { + index = this.rl.line.length ? Number(this.rl.line) - 1 : 0; + } + this.lastKey = ''; if (this.opt.choices.getChoice(index)) { this.selected = index; @@ -178,7 +188,9 @@ class RawListPrompt extends Base { onArrowKey(type) { this.selected = incrementListIndex(this.selected, type, this.opt); - this.rl.line = String(this.selected + 1); + this.hiddenLine = String(this.selected + 1); + this.rl.line = ''; + this.lastKey = 'arrow'; } }