Removes diacritics from @mentions
This commit is contained in:
@@ -6,6 +6,7 @@ import { get } from 'lodash';
|
|||||||
|
|
||||||
import type { ConversationType } from '../state/ducks/conversations';
|
import type { ConversationType } from '../state/ducks/conversations';
|
||||||
import { filter, map } from '../util/iterables';
|
import { filter, map } from '../util/iterables';
|
||||||
|
import { removeDiacritics } from '../util/removeDiacritics';
|
||||||
|
|
||||||
const FUSE_OPTIONS = {
|
const FUSE_OPTIONS = {
|
||||||
location: 0,
|
location: 0,
|
||||||
@@ -30,7 +31,7 @@ const FUSE_OPTIONS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const segmenter = new Intl.Segmenter(undefined, { granularity: 'word' });
|
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 wordlikeSegments = filter(segments, segment => segment.isWordLike);
|
||||||
const wordlikes = map(wordlikeSegments, segment => segment.segment);
|
const wordlikes = map(wordlikeSegments, segment => segment.segment);
|
||||||
return Array.from(wordlikes);
|
return Array.from(wordlikes);
|
||||||
@@ -81,7 +82,9 @@ export class MemberRepository {
|
|||||||
this.isFuseReady = true;
|
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) {
|
if (omit) {
|
||||||
return results.filter(({ id }) => id !== omit.id);
|
return results.filter(({ id }) => id !== omit.id);
|
||||||
|
@@ -28,6 +28,7 @@ const me: ConversationType = getDefaultConversationWithUuid({
|
|||||||
isMe: true,
|
isMe: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO diacritic
|
||||||
const members: Array<ConversationType> = [
|
const members: Array<ConversationType> = [
|
||||||
getDefaultConversationWithUuid({
|
getDefaultConversationWithUuid({
|
||||||
id: '555444',
|
id: '555444',
|
||||||
@@ -49,6 +50,16 @@ const members: Array<ConversationType> = [
|
|||||||
markedUnread: false,
|
markedUnread: false,
|
||||||
areWeAdmin: 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,
|
me,
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -246,6 +257,23 @@ describe('MentionCompletion', () => {
|
|||||||
assert.equal(withTrailingSpace, true);
|
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]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user