Prefer canonical aliases over non-canonical ones
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
d0ea842f1e
commit
7bf230e665
1 changed files with 6 additions and 0 deletions
|
@ -32,6 +32,11 @@ import SettingsStore from "../settings/SettingsStore";
|
||||||
|
|
||||||
const ROOM_REGEX = /\B#\S*/g;
|
const ROOM_REGEX = /\B#\S*/g;
|
||||||
|
|
||||||
|
// Prefer canonical aliases over non-canonical ones
|
||||||
|
function canonicalScore(displayedAlias: string, room: Room): number {
|
||||||
|
return displayedAlias === room.getCanonicalAlias() ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
function matcherObject(room: Room, displayedAlias: string, matchName = "") {
|
function matcherObject(room: Room, displayedAlias: string, matchName = "") {
|
||||||
return {
|
return {
|
||||||
room,
|
room,
|
||||||
|
@ -97,6 +102,7 @@ export default class RoomProvider extends AutocompleteProvider {
|
||||||
const matchedString = command[0];
|
const matchedString = command[0];
|
||||||
completions = this.matcher.match(matchedString, limit);
|
completions = this.matcher.match(matchedString, limit);
|
||||||
completions = sortBy(completions, [
|
completions = sortBy(completions, [
|
||||||
|
(c) => canonicalScore(c.displayedAlias, c.room),
|
||||||
(c) => c.displayedAlias.length,
|
(c) => c.displayedAlias.length,
|
||||||
]);
|
]);
|
||||||
completions = uniqBy(completions, (match) => match.room);
|
completions = uniqBy(completions, (match) => match.room);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue