Skip to content

Commit

Permalink
fixes #1025 rawlist stops handling arrow keys after bad input (#1026)
Browse files Browse the repository at this point in the history
Co-authored-by: Doug Owings <doug@dougowings.net>
  • Loading branch information
owings1 and owings1 committed Jul 14, 2021
1 parent 44ba021 commit 58de622
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/inquirer/lib/prompts/rawlist.js
Expand Up @@ -73,9 +73,11 @@ class RawListPrompt extends Base {
validation.success.forEach(this.onEnd.bind(this));
validation.error.forEach(this.onError.bind(this));

events.normalizedUpKey.pipe(takeUntil(events.line)).forEach(this.onUpKey.bind(this));
events.normalizedUpKey
.pipe(takeUntil(validation.success))
.forEach(this.onUpKey.bind(this));
events.normalizedDownKey
.pipe(takeUntil(events.line))
.pipe(takeUntil(validation.success))
.forEach(this.onDownKey.bind(this));
events.keypress
.pipe(takeUntil(validation.success))
Expand Down
16 changes: 16 additions & 0 deletions packages/inquirer/test/specs/prompts/rawlist.js
Expand Up @@ -110,6 +110,22 @@ describe('`rawlist` prompt', () => {
this.rl.emit('line', this.rl.line);
});

it('should allow for arrow navigation after invalid input', function (done) {
this.rawlist
.run()
.then((answer) => {
expect(answer).to.equal('bar');
done();
})
.catch(done);

this.rl.emit('line', 'blah');
this.rl.input.emit('keypress', '', { name: 'down' });
this.rl.input.emit('keypress', '', { name: 'down' });
this.rl.input.emit('keypress', '', { name: 'up' });
this.rl.emit('line', this.rl.line);
});

describe('going out of boundaries', () => {
beforeEach(function () {
this.pressKey = function (dir, times) {
Expand Down

0 comments on commit 58de622

Please sign in to comment.