From b13dae1fc66144d37206317e1f9923df4cab090d Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Wed, 31 Mar 2021 22:45:53 -0400 Subject: [PATCH] Ignore punctuation when filtering rooms Signed-off-by: Robin Townsend --- .../room-list/filters/NameFilterCondition.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/stores/room-list/filters/NameFilterCondition.ts b/src/stores/room-list/filters/NameFilterCondition.ts index 88edaecfb6..ad487139d5 100644 --- a/src/stores/room-list/filters/NameFilterCondition.ts +++ b/src/stores/room-list/filters/NameFilterCondition.ts @@ -66,12 +66,17 @@ export class NameFilterCondition extends EventEmitter implements IFilterConditio return this.matches(room.name); } - public matches(val: string): boolean { + private normalize(val: string): string { // Note: we have to match the filter with the removeHiddenChars() room name because the // function strips spaces and other characters (M becomes RN for example, in lowercase). - // We also doubly convert to lowercase to work around oddities of the library. - const noSecretsFilter = removeHiddenChars(this.search.toLowerCase()).toLowerCase(); - const noSecretsName = removeHiddenChars(val.toLowerCase()).toLowerCase(); - return noSecretsName.includes(noSecretsFilter); + return removeHiddenChars(val.toLowerCase()) + // Strip all punctuation + .replace(/[\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~\u2000-\u206f\u2e00-\u2e7f]/g, "") + // We also doubly convert to lowercase to work around oddities of the library. + .toLowerCase(); + } + + public matches(val: string): boolean { + return this.normalize(val).includes(this.normalize(this.search)); } }