diff --git a/src/autocomplete/QueryMatcher.js b/src/autocomplete/QueryMatcher.js index 37ea169c29..f85d518fee 100644 --- a/src/autocomplete/QueryMatcher.js +++ b/src/autocomplete/QueryMatcher.js @@ -69,6 +69,12 @@ export default class QueryMatcher { if (this.options.shouldMatchWordsOnly === undefined) { this.options.shouldMatchWordsOnly = true; } + + // By default, match anywhere in the string being searched. If enabled, only return + // matches that are prefixed with the query. + if (this.options.shouldMatchPrefix === undefined) { + this.options.shouldMatchPrefix = false; + } } setObjects(objects: Array) { @@ -87,7 +93,7 @@ export default class QueryMatcher { resultKey = resultKey.replace(/[^\w]/g, ''); } const index = resultKey.indexOf(query); - if (index !== -1) { + if (index !== -1 && (!this.options.shouldMatchPrefix || index === 0)) { results.push({key, index}); } }); diff --git a/src/autocomplete/UserProvider.js b/src/autocomplete/UserProvider.js index b6be106a93..f1fa3a9236 100644 --- a/src/autocomplete/UserProvider.js +++ b/src/autocomplete/UserProvider.js @@ -37,10 +37,11 @@ export default class UserProvider extends AutocompleteProvider { constructor() { super(USER_REGEX, { - keys: ['name', 'userId'], + keys: ['name'], }); this.matcher = new FuzzyMatcher([], { - keys: ['name', 'userId'], + keys: ['name'], + shouldMatchPrefix: true, }); }