When sorting completions, use matched string, not entire query

Otherwise the results vary depending on where you start autocompleting in your message. We only care about the matched string.
This commit is contained in:
Luke Barnard 2017-08-02 10:09:00 +01:00
parent b632c9132c
commit 72c1cf9288
2 changed files with 8 additions and 7 deletions

View file

@ -63,9 +63,10 @@ export default class RoomProvider extends AutocompleteProvider {
displayedAlias: getDisplayAliasForRoom(room),
};
}));
completions = this.matcher.match(command[0]);
const matchedString = command[0];
completions = this.matcher.match(matchedString);
completions = _sortBy(completions, [
(c) => score(query, c.displayedAlias),
(c) => score(matchedString, c.displayedAlias),
(c) => c.displayedAlias.length,
]).map((room) => {
const displayAlias = getDisplayAliasForRoom(room.room) || room.roomId;