Fix user autocompleting

This rewrites quite a lot of QueryMatcher.
 * Remove FuzzyMatcher which was a whole file of commented out code
   that just deferred to QueryMatcher
 * Simplify & remove some cruft from QueryMatcher, eg. most of the
   KeyMap stuff was completely unused.
 * Don't rely on object iteration order, which fixes a bug where
   users whose display names were entirely numeric would always
   appear first...
 * Add options.funcs to QueryMatcher to allow for indexing by things
   other than keys on the objects
 * Use above to index users by username minus the leading '@'
 * Don't include the '@' in the query when autocomple is triggered
   by typing '@'.

Fixes https://github.com/vector-im/riot-web/issues/6782
This commit is contained in:
David Baker 2018-10-11 18:34:01 +01:00
parent b267798010
commit 9c8c84485a
2 changed files with 60 additions and 58 deletions

View file

@ -45,7 +45,8 @@ export default class UserProvider extends AutocompleteProvider {
super(USER_REGEX, FORCED_USER_REGEX);
this.room = room;
this.matcher = new QueryMatcher([], {
keys: ['name', 'userId'],
keys: ['name'],
funcs: [obj => obj.userId.slice(1)], // index by user id minus the leading '@'
shouldMatchPrefix: true,
shouldMatchWordsOnly: false,
});