Skip to content

Commit

Permalink
fix input of "rawlist" (#1089)
Browse files Browse the repository at this point in the history
Co-authored-by: Rob O’Connor <rob@roboconnor.com>
Co-authored-by: Simon Boudrias <admin@simonboudrias.com>
  • Loading branch information
3 people committed Mar 9, 2022
1 parent baf4efe commit cdc867a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/inquirer/lib/prompts/rawlist.js
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
}
}

Expand Down

0 comments on commit cdc867a

Please sign in to comment.