2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-06 07:20:40 +00:00

fix(utils): fix replacement of multiple emojis in a row

This commit is contained in:
Vjacheslav Trushkin 2022-12-27 23:27:05 +02:00
parent 2fb77d5bf6
commit 92a2624d98
3 changed files with 89 additions and 2 deletions

View File

@ -3,7 +3,7 @@
"type": "module",
"description": "Common functions for working with Iconify icon sets used by various packages.",
"author": "Vjacheslav Trushkin",
"version": "2.0.5",
"version": "2.0.6",
"license": "MIT",
"bugs": "https://github.com/iconify/iconify/issues",
"homepage": "https://iconify.design/",

View File

@ -119,7 +119,7 @@ export function sortEmojiMatchesInText(
const check = (start: number, end: number): boolean => {
for (let i = 0; i < ranges.length; i++) {
if (start < ranges[i].end && end >= ranges[i].start) {
if (start < ranges[i].end && end > ranges[i].start) {
return false;
}
}

View File

@ -238,4 +238,91 @@ describe('Finding emojis in text', () => {
},
]);
});
it('Sequences without spaces', () => {
const regex = createOptimisedRegex(['1F63A', '1F638', '1F639']);
const emoji1 = String.fromCodePoint(0x1f63a);
const emoji2 = String.fromCodePoint(0x1f638);
const emoji3 = String.fromCodePoint(0x1f639);
const content = emoji1 + emoji2 + emoji3 + emoji1 + emoji2;
const matches = getEmojiMatchesInText(regex, content);
expect(matches).toEqual([
{
match: '\uD83D\uDE38',
sequence: [0x1f638],
keyword: '1f638',
regexp: 0,
},
{
match: '\uD83D\uDE39',
sequence: [0x1f639],
keyword: '1f639',
regexp: 0,
},
{
match: '\uD83D\uDE3A',
sequence: [0x1f63a],
keyword: '1f63a',
regexp: 0,
},
]);
const sortedMatches = sortEmojiMatchesInText(content, matches);
expect(sortedMatches).toEqual([
// Same order as in content
{
match: {
match: '\uD83D\uDE3A',
sequence: [0x1f63a],
keyword: '1f63a',
regexp: 0,
},
prev: '',
next: '',
},
{
match: {
match: '\uD83D\uDE38',
sequence: [0x1f638],
keyword: '1f638',
regexp: 0,
},
prev: '',
next: '',
},
{
match: {
match: '\uD83D\uDE39',
sequence: [0x1f639],
keyword: '1f639',
regexp: 0,
},
prev: '',
next: '',
},
{
match: {
match: '\uD83D\uDE3A',
sequence: [0x1f63a],
keyword: '1f63a',
regexp: 0,
},
prev: '',
next: '',
},
{
match: {
match: '\uD83D\uDE38',
sequence: [0x1f638],
keyword: '1f638',
regexp: 0,
},
prev: '',
next: '',
},
]);
});
});