Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(prompt): set list index to 0 instead of 1 when selecting a group option #727

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions prompt/_generic_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export abstract class GenericList<
protected submitGroupOption(selectedOption: TGroup) {
this.parentOptions.push(selectedOption);
this.match();
this.listIndex = 1;
this.listIndex = 0;
}

protected isBackButton(option: TOption | TGroup | undefined): boolean {
Expand Down Expand Up @@ -584,10 +584,13 @@ export abstract class GenericList<
if (
this.isKey(this.settings.keys, "open", event) &&
isOptionGroup(this.selectedOption) &&
!this.isBackButton(this.selectedOption) &&
!this.isSearchSelected()
) {
this.submitGroupOption(this.selectedOption);
if (this.isBackButton(this.selectedOption)) {
this.selectNext();
} else {
this.submitGroupOption(this.selectedOption);
}
} else if (
this.isKey(this.settings.keys, "back", event) &&
(this.isBackButton(this.selectedOption) || event.name === "escape") &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,42 @@ snapshot[`checkbox prompt with groups and breadcrumb > should render breadcrumb
stdout:
"? Select an option
❯ ✘ 📁 Foo\\x1b[1A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo
✘ 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo
❯ ✘ 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo › Bar
✘ 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo › Bar
❯ ✘ 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo › Bar › Baz
✘ 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo › Bar › Baz
❯ ✘ 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo › Bar › Baz › Beep
✘ 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo › Bar › Baz › Beep
❯ ✘ 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo › .. › Baz › Beep › Boop
✘ 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo › .. › Baz › Beep › Boop
❯ ✘ 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo › .. › Beep › Boop › Fiz
✘ Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo › .. › Beep › Boop › Fiz
❯ ✘ Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo › .. › Beep › Boop › Fiz
❯ ✘ Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
Expand All @@ -42,21 +63,42 @@ snapshot[`checkbox prompt with custom breadcrumb separator > should render bread
stdout:
"? Select an option
❯ ✘ 📁 Foo\\x1b[1A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo
✘ 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo
❯ ✘ 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo # Bar
✘ 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo # Bar
❯ ✘ 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo # Bar # Baz
✘ 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo # Bar # Baz
❯ ✘ 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo # Bar # Baz # Beep
✘ 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo # Bar # Baz # Beep
❯ ✘ 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo # .. # Baz # Beep # Boop
✘ 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo # .. # Baz # Beep # Boop
❯ ✘ 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Foo # .. # Beep # Boop # Fiz
✘ Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo # .. # Beep # Boop # Fiz
❯ ✘ Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Foo # .. # Beep # Boop # Fiz
❯ ✘ Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,42 @@ snapshot[`checkbox prompt with groups and breadcrumb > should render breadcrumb
stdout:
"? Select an option
❯ × 📁 Foo\\x1b[1A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo
× 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo
❯ × 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo » Bar
× 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo » Bar
❯ × 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo » Bar » Baz
× 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo » Bar » Baz
❯ × 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo » Bar » Baz » Beep
× 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo » Bar » Baz » Beep
❯ × 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo » .. » Baz » Beep » Boop
× 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo » .. » Baz » Beep » Boop
❯ × 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo » .. » Beep » Boop » Fiz
× Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo » .. » Beep » Boop » Fiz
❯ × Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo » .. » Beep » Boop » Fiz
❯ × Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
Expand All @@ -42,21 +63,42 @@ snapshot[`checkbox prompt with custom breadcrumb separator > should render bread
stdout:
"? Select an option
❯ × 📁 Foo\\x1b[1A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo
× 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo
❯ × 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo # Bar
× 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo # Bar
❯ × 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo # Bar # Baz
× 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo # Bar # Baz
❯ × 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo # Bar # Baz # Beep
× 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo # Bar # Baz # Beep
❯ × 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo # .. # Baz # Beep # Boop
× 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo # .. # Baz # Beep # Boop
❯ × 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Foo # .. # Beep # Boop # Fiz
× Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo # .. # Beep # Boop # Fiz
❯ × Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Foo # .. # Beep # Boop # Fiz
❯ × Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ stdout:
✘ Foo
✘ Bar
❯ ✘ 📁 Baz\\x1b[3A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ ✘ 📂 Baz
✘ Beep
✘ Boop\\x1b[3A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
✘ 📂 Baz
❯ ✘ Beep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ stdout:
× Foo
× Bar
❯ × 📁 Baz\\x1b[3A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ × 📂 Baz
× Beep
× Boop\\x1b[3A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
× 📂 Baz
❯ × Beep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,39 @@ snapshot[`select prompt with groups and breadcrumb > should render breadcrumb 1`
stdout:
"? Select an option
❯ 📁 Foo\\x1b[1A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo
📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo
❯ 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo › Bar
📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo › Bar
❯ 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo › Bar › Baz
📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo › Bar › Baz
❯ 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo › Bar › Baz › Beep
📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo › Bar › Baz › Beep
❯ 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo › .. › Baz › Beep › Boop
📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo › .. › Baz › Beep › Boop
❯ 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo › .. › Beep › Boop › Fiz
Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo › .. › Beep › Boop › Fiz
❯ Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
Expand All @@ -32,21 +50,39 @@ snapshot[`select prompt with custom breadcrumb separator > should render breadcr
stdout:
"? Select an option
❯ 📁 Foo\\x1b[1A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo
📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo
❯ 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo # Bar
📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo # Bar
❯ 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo # Bar # Baz
📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo # Bar # Baz
❯ 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo # Bar # Baz # Beep
📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo # Bar # Baz # Beep
❯ 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo # .. # Baz # Beep # Boop
📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo # .. # Baz # Beep # Boop
❯ 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo # .. # Beep # Boop # Fiz
Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo # .. # Beep # Boop # Fiz
❯ Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,39 @@ snapshot[`select prompt with groups and breadcrumb > should render breadcrumb 1`
stdout:
"? Select an option
❯ 📁 Foo\\x1b[1A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo
📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo
❯ 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo » Bar
📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo » Bar
❯ 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo » Bar » Baz
📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo » Bar » Baz
❯ 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo » Bar » Baz » Beep
📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo » Bar » Baz » Beep
❯ 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo » .. » Baz » Beep » Boop
📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo » .. » Baz » Beep » Boop
❯ 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo » .. » Beep » Boop » Fiz
Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo » .. » Beep » Boop » Fiz
❯ Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
Expand All @@ -32,21 +50,39 @@ snapshot[`select prompt with custom breadcrumb separator > should render breadcr
stdout:
"? Select an option
❯ 📁 Foo\\x1b[1A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo
📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo
❯ 📁 Bar\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo # Bar
📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo # Bar
❯ 📁 Baz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo # Bar # Baz
📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo # Bar # Baz
❯ 📁 Beep\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo # Bar # Baz # Beep
📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo # Bar # Baz # Beep
❯ 📁 Boop\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo # .. # Baz # Beep # Boop
📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo # .. # Baz # Beep # Boop
❯ 📁 Fiz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Foo # .. # Beep # Boop # Fiz
Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Foo # .. # Beep # Boop # Fiz
❯ Faz\\x1b[2A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ stdout:
Foo
Bar
❯ 📁 Baz\\x1b[3A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
❮ 📂 Baz
Beep
Boop\\x1b[3A\\x1b[0G\\x1b[?25l\\x1b[G\\x1b[0J
? Select an option
📂 Baz
❯ Beep
Expand Down
Loading
Loading