Add a limit option for autocomplete results (#6016)
This commit is contained in:
parent
eea6ba6825
commit
bd2917aa69
11 changed files with 75 additions and 20 deletions
|
@ -87,7 +87,7 @@ export default class QueryMatcher<T extends Object> {
|
|||
}
|
||||
}
|
||||
|
||||
match(query: string): T[] {
|
||||
match(query: string, limit = -1): T[] {
|
||||
query = this.processQuery(query);
|
||||
if (this._options.shouldMatchWordsOnly) {
|
||||
query = query.replace(/[^\w]/g, '');
|
||||
|
@ -129,7 +129,10 @@ export default class QueryMatcher<T extends Object> {
|
|||
});
|
||||
|
||||
// Now map the keys to the result objects. Also remove any duplicates.
|
||||
return uniq(matches.map((match) => match.object));
|
||||
const dedupped = uniq(matches.map((match) => match.object));
|
||||
const maxLength = limit === -1 ? dedupped.length : limit;
|
||||
|
||||
return dedupped.slice(0, maxLength);
|
||||
}
|
||||
|
||||
private processQuery(query: string): string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue