Skip to content

Commit

Permalink
Fix autocomplete issues (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
elie-g authored and terkelg committed Mar 10, 2019
1 parent b6a5501 commit 9186cd5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 4 additions & 2 deletions lib/elements/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ class AutocompletePrompt extends Prompt {
if (this.page >= this.suggestions.length - 1)
return this.bell();
this.page++;
this.moveSelect(this.select);
this.moveSelect(0);
this.render();
}

prevPage() {
if (this.page <= 0)
return this.bell();
this.page--;
this.moveSelect(this.select);
this.moveSelect(0);
this.render();
}

Expand Down Expand Up @@ -236,6 +236,7 @@ class AutocompletePrompt extends Prompt {
if (suggestions && !this.isFallback) {
prompt += suggestions;
if (this.suggestions.length > 1) {
this.lineCount++;
prompt += color.blue(`\nPage ${this.page+1}/${this.suggestions.length}`);
}
} else {
Expand All @@ -244,6 +245,7 @@ class AutocompletePrompt extends Prompt {
? getTitle(this.choices, fallbackIndex)
: this.fallback;
prompt += `\n${color.gray(fallbackTitle)}`;
this.lineCount++;
}
}

Expand Down
6 changes: 2 additions & 4 deletions lib/elements/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,8 @@ class DatePrompt extends Prompt {
style.symbol(this.done, this.aborted),
color.bold(this.msg),
style.delimiter(false),
this.parts.reduce((arr, p, idx) =>
arr.concat(idx === this.cursor
? color.cyan().underline(p.toString())
: p), []).join(''),
this.parts.reduce((arr, p, idx) => arr.concat(idx === this.cursor && !this.done ? color.cyan().underline(p.toString()) : p), [])
.join(''),
].join(' ');

let position = '';
Expand Down
16 changes: 8 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ If you want to predefine selected values, give the choice object an `selected` p
> Interactive auto complete prompt.
The prompt will list options based on user input. Type to filter the list.
Use <kbd>up</kbd>/<kbd>down</kbd> to navigate. Use <kbd>tab</kbd> to cycle the result. Use <kbd>Page Up</kbd>/<kbd>Page Down</kbd> to change page. Hit <kbd>enter</kbd> to select the highlighted item below the prompt.
Use <kbd></kbd>/<kbd></kbd> to navigate. Use <kbd>tab</kbd> to cycle the result. Use <kbd>Page Up</kbd>/<kbd>Page Down</kbd> (on Mac: <kbd>fn</kbd> + <kbd>⇧</kbd> / <kbd>⇩</kbd>) to change page. Hit <kbd>enter</kbd> to select the highlighted item below the prompt.

The default suggests function is sorting based on the `title` property of the choices.
You can overwrite how choices are being filtered by passing your own suggest function.
Expand All @@ -709,7 +709,7 @@ You can overwrite how choices are being filtered by passing your own suggest fun
{ title: 'Clooney', value: 'silver-fox' },
{ title: 'Gyllenhaal' },
{ title: 'Gibson' },
{ title: 'Grant' },
{ title: 'Grant' }
]
}
```
Expand All @@ -731,7 +731,7 @@ You can overwrite how choices are being filtered by passing your own suggest fun
Example on what a `suggest` function might look like:
```js
const suggestByTitle = (input, choices) =>
Promise.resolve(choices.filter(i => i.title.slice(0, input.length) === input))
Promise.resolve(choices.filter(i => i.title.slice(0, input.length) === input))
```


Expand Down Expand Up @@ -769,20 +769,20 @@ Default locales:
```javascript
{
months: [
'January', 'February', 'March', 'April',
'January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'
],
'September', 'October', 'November', 'December'
],
monthsShort: [
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
],
weekdays: [
'Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday'
],
weekdaysShort: [
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
]
}
```
Expand Down

0 comments on commit 9186cd5

Please sign in to comment.