Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Suggestion.isFiltered. Fixes #1073
  • Loading branch information
vlad-shatskyi committed Jun 5, 2017
1 parent b20b700 commit c2c6c1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Autocompletion.ts
Expand Up @@ -29,6 +29,7 @@ export const getSuggestions = async({
const suggestionsFromHistory = prefixMatchesInHistory.map(match => new Suggestion({
value: match,
promptSerializer: replaceAllPromptSerializer,
isFiltered: true,
style: styles.history,
}));

Expand All @@ -42,10 +43,8 @@ export const getSuggestions = async({
aliases: aliases,
});

const applicableSuggestions = _.uniqBy(
[...firstThreeFromHistory, ...suggestions, ...remainderFromHistory],
suggestion => suggestion.value,
).filter(suggestion => suggestion.value.toLowerCase().startsWith(node.value.toLowerCase()));
const uniqueSuggestions = _.uniqBy([...firstThreeFromHistory, ...suggestions, ...remainderFromHistory], suggestion => suggestion.value);
const applicableSuggestions = uniqueSuggestions.filter(suggestion => suggestion.isFiltered || suggestion.value.toLowerCase().startsWith(node.value.toLowerCase()));

if (applicableSuggestions.length === 1) {
const suggestion = applicableSuggestions[0];
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/autocompletion_utils/Common.ts
Expand Up @@ -26,6 +26,7 @@ interface SuggestionAttributes {
displayValue: string;
synopsis: string;
description: string;
isFiltered: boolean;
style: Style;
space: boolean;
promptSerializer: PromptSerializer;
Expand Down Expand Up @@ -72,6 +73,10 @@ export class Suggestion {
return this.attributes.displayValue || this.value;
}

get isFiltered(): boolean {
return this.attributes.isFiltered || false;
}

get promptSerializer(): PromptSerializer {
return this.attributes.promptSerializer || defaultPromptSerializer;
}
Expand Down

0 comments on commit c2c6c1c

Please sign in to comment.