From d2b06413f3622f07298421b77e31e8929477b09d Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Wed, 14 Jun 2023 14:24:34 -0700 Subject: [PATCH] Removes diacritics from @mentions --- ts/quill/memberRepository.ts | 7 +++-- .../quill/mentions/completion_test.tsx | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ts/quill/memberRepository.ts b/ts/quill/memberRepository.ts index 178ef91e6..761e9875e 100644 --- a/ts/quill/memberRepository.ts +++ b/ts/quill/memberRepository.ts @@ -6,6 +6,7 @@ import { get } from 'lodash'; import type { ConversationType } from '../state/ducks/conversations'; import { filter, map } from '../util/iterables'; +import { removeDiacritics } from '../util/removeDiacritics'; const FUSE_OPTIONS = { location: 0, @@ -30,7 +31,7 @@ const FUSE_OPTIONS = { } const segmenter = new Intl.Segmenter(undefined, { granularity: 'word' }); - const segments = segmenter.segment(rawValue); + const segments = segmenter.segment(removeDiacritics(rawValue)); const wordlikeSegments = filter(segments, segment => segment.isWordLike); const wordlikes = map(wordlikeSegments, segment => segment.segment); return Array.from(wordlikes); @@ -81,7 +82,9 @@ export class MemberRepository { this.isFuseReady = true; } - const results = this.fuse.search(pattern).map(result => result.item); + const results = this.fuse + .search(removeDiacritics(pattern)) + .map(result => result.item); if (omit) { return results.filter(({ id }) => id !== omit.id); diff --git a/ts/test-electron/quill/mentions/completion_test.tsx b/ts/test-electron/quill/mentions/completion_test.tsx index b13756aa8..a73f435ed 100644 --- a/ts/test-electron/quill/mentions/completion_test.tsx +++ b/ts/test-electron/quill/mentions/completion_test.tsx @@ -28,6 +28,7 @@ const me: ConversationType = getDefaultConversationWithUuid({ isMe: true, }); +// TODO diacritic const members: Array = [ getDefaultConversationWithUuid({ id: '555444', @@ -49,6 +50,16 @@ const members: Array = [ markedUnread: false, areWeAdmin: false, }), + getDefaultConversationWithUuid({ + areWeAdmin: false, + firstName: 'Zoë', + id: '999977', + lastUpdated: Date.now(), + markedUnread: false, + profileName: 'Zoë A', + title: 'Zoë Aurélien', + type: 'direct', + }), me, ]; @@ -246,6 +257,23 @@ describe('MentionCompletion', () => { assert.equal(withTrailingSpace, true); }); }); + + describe('diacritics', () => { + it('finds a member with diacritics using non-diacritic chars', () => { + const text = '@zoe'; + const index = text.length; + mockQuill.getSelection?.returns({ index }); + const blot = { + text, + }; + mockQuill.getLeaf?.returns([blot, index]); + mentionCompletion.completeMention(2); + + const [member] = insertMentionStub.getCall(0).args; + + assert.equal(member, members[2]); + }); + }); }); }); });