From f091f16d286a826a7a4a69e5d69d137f67795000 Mon Sep 17 00:00:00 2001 From: gpoitch Date: Thu, 6 Aug 2020 10:29:41 -0400 Subject: [PATCH] Loop cursor on all select-style prompts --- lib/elements/autocomplete.js | 14 ++++++++++---- lib/elements/select.js | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/elements/autocomplete.js b/lib/elements/autocomplete.js index b4924144..6cb050d3 100644 --- a/lib/elements/autocomplete.js +++ b/lib/elements/autocomplete.js @@ -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(); } diff --git a/lib/elements/select.js b/lib/elements/select.js index 8d4fea94..cd41395f 100644 --- a/lib/elements/select.js +++ b/lib/elements/select.js @@ -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(); }