Skip to content

Commit

Permalink
Loop cursor on all select-style prompts (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoitch committed Sep 8, 2020
1 parent 6c51699 commit abe3c01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions lib/elements/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,20 @@ class AutocompletePrompt extends Prompt {
}

up() {
if (this.select <= 0) return this.bell();
this.moveSelect(this.select - 1);
if (this.select === 0) {
this.moveSelect(this.suggestions.length - 1);
} else {
this.moveSelect(this.select - 1);
}
this.render();
}

down() {
if (this.select >= this.suggestions.length - 1) return this.bell();
this.moveSelect(this.select + 1);
if (this.select === this.suggestions.length - 1) {
this.moveSelect(0);
} else {
this.moveSelect(this.select + 1);
}
this.render();
}

Expand Down
14 changes: 10 additions & 4 deletions lib/elements/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,20 @@ class SelectPrompt extends Prompt {
}

up() {
if (this.cursor === 0) return this.bell();
this.moveCursor(this.cursor - 1);
if (this.cursor === 0) {
this.moveCursor(this.choices.length - 1);
} else {
this.moveCursor(this.cursor - 1);
}
this.render();
}

down() {
if (this.cursor === this.choices.length - 1) return this.bell();
this.moveCursor(this.cursor + 1);
if (this.cursor === this.choices.length - 1) {
this.moveCursor(0);
} else {
this.moveCursor(this.cursor + 1);
}
this.render();
}

Expand Down

0 comments on commit abe3c01

Please sign in to comment.