Skip to content

Commit cdc867a

Browse files
RobInNYCRob O’ConnorSBoudrias
authored
fix input of "rawlist" (#1089)
Co-authored-by: Rob O’Connor <rob@roboconnor.com> Co-authored-by: Simon Boudrias <admin@simonboudrias.com>
1 parent baf4efe commit cdc867a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/inquirer/lib/prompts/rawlist.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class RawListPrompt extends Base {
1515
constructor(questions, rl, answers) {
1616
super(questions, rl, answers);
1717

18+
this.hiddenLine = '';
19+
this.lastKey = '';
20+
1821
if (!this.opt.choices) {
1922
this.throwParamError('choices');
2023
}
@@ -145,7 +148,14 @@ class RawListPrompt extends Base {
145148
*/
146149

147150
onKeypress() {
148-
const index = this.rl.line.length ? Number(this.rl.line) - 1 : 0;
151+
let index;
152+
153+
if (this.lastKey === 'arrow') {
154+
index = this.hiddenLine.length ? Number(this.hiddenLine) - 1 : 0;
155+
} else {
156+
index = this.rl.line.length ? Number(this.rl.line) - 1 : 0;
157+
}
158+
this.lastKey = '';
149159

150160
if (this.opt.choices.getChoice(index)) {
151161
this.selected = index;
@@ -178,7 +188,9 @@ class RawListPrompt extends Base {
178188

179189
onArrowKey(type) {
180190
this.selected = incrementListIndex(this.selected, type, this.opt);
181-
this.rl.line = String(this.selected + 1);
191+
this.hiddenLine = String(this.selected + 1);
192+
this.rl.line = '';
193+
this.lastKey = 'arrow';
182194
}
183195
}
184196

0 commit comments

Comments
 (0)