make Accent Insensitive match more generic and apply to rooms too

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2018-06-23 02:10:31 +01:00
parent 104e8d9cba
commit 54bccd2016
No known key found for this signature in database
GPG key ID: 3F879DA5AD802A5E
3 changed files with 8 additions and 5 deletions

View file

@ -43,6 +43,10 @@ export type Completion = {
href: ?string,
};
export function stripDiacritics(str: string): string {
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
}
const PROVIDERS = [
UserProvider,
RoomProvider,

View file

@ -2,6 +2,7 @@
Copyright 2016 Aviral Dasgupta
Copyright 2017 Vector Creations Ltd
Copyright 2017, 2018 New Vector Ltd
Copyright 2018 Michael Telatynski <7t3chguy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -27,6 +28,7 @@ import sdk from '../index';
import _sortBy from 'lodash/sortBy';
import {makeRoomPermalink} from "../matrix-to";
import type {Completion, SelectionRange} from "./Autocompleter";
import {stripDiacritics} from "./Autocompleter";
const ROOM_REGEX = /(?=#)(\S*)/g;
@ -71,7 +73,7 @@ export default class RoomProvider extends AutocompleteProvider {
};
}));
const matchedString = command[0];
completions = this.matcher.match(matchedString);
completions = this.matcher.match(stripDiacritics(matchedString));
completions = _sortBy(completions, [
(c) => score(matchedString, c.displayedAlias),
(c) => c.displayedAlias.length,

View file

@ -30,13 +30,10 @@ import MatrixClientPeg from '../MatrixClientPeg';
import type {MatrixEvent, Room, RoomMember, RoomState} from 'matrix-js-sdk';
import {makeUserPermalink} from "../matrix-to";
import type {Completion, SelectionRange} from "./Autocompleter";
import {stripDiacritics} from "./Autocompleter";
const USER_REGEX = /@\S*/g;
function stripDiacritics(str: string): string {
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
}
export default class UserProvider extends AutocompleteProvider {
users: Array<RoomMember> = null;
room: Room = null;