From 54bccd20160356ef96ce17c8ce1f946399582124 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 23 Jun 2018 02:10:31 +0100 Subject: [PATCH] make Accent Insensitive match more generic and apply to rooms too Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/autocomplete/Autocompleter.js | 4 ++++ src/autocomplete/RoomProvider.js | 4 +++- src/autocomplete/UserProvider.js | 5 +---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/autocomplete/Autocompleter.js b/src/autocomplete/Autocompleter.js index f5fec4c502..b8988e889f 100644 --- a/src/autocomplete/Autocompleter.js +++ b/src/autocomplete/Autocompleter.js @@ -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, diff --git a/src/autocomplete/RoomProvider.js b/src/autocomplete/RoomProvider.js index c222ae95d4..e4cc9567a0 100644 --- a/src/autocomplete/RoomProvider.js +++ b/src/autocomplete/RoomProvider.js @@ -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, diff --git a/src/autocomplete/UserProvider.js b/src/autocomplete/UserProvider.js index 9fc59e578d..c98304fff8 100644 --- a/src/autocomplete/UserProvider.js +++ b/src/autocomplete/UserProvider.js @@ -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 = null; room: Room = null;