Removes diacritics from @mentions
This commit is contained in:
parent
b1ee0a1d68
commit
d2b06413f3
2 changed files with 33 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -28,6 +28,7 @@ const me: ConversationType = getDefaultConversationWithUuid({
|
|||
isMe: true,
|
||||
});
|
||||
|
||||
// TODO diacritic
|
||||
const members: Array<ConversationType> = [
|
||||
getDefaultConversationWithUuid({
|
||||
id: '555444',
|
||||
|
@ -49,6 +50,16 @@ const members: Array<ConversationType> = [
|
|||
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]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue