mirror of
https://github.com/iconify/iconify.git
synced 2025-01-07 15:44:05 +00:00
fix(utils): fix replacement of multiple emojis in a row
This commit is contained in:
parent
2fb77d5bf6
commit
92a2624d98
@ -3,7 +3,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "Common functions for working with Iconify icon sets used by various packages.",
|
"description": "Common functions for working with Iconify icon sets used by various packages.",
|
||||||
"author": "Vjacheslav Trushkin",
|
"author": "Vjacheslav Trushkin",
|
||||||
"version": "2.0.5",
|
"version": "2.0.6",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": "https://github.com/iconify/iconify/issues",
|
"bugs": "https://github.com/iconify/iconify/issues",
|
||||||
"homepage": "https://iconify.design/",
|
"homepage": "https://iconify.design/",
|
||||||
|
@ -119,7 +119,7 @@ export function sortEmojiMatchesInText(
|
|||||||
|
|
||||||
const check = (start: number, end: number): boolean => {
|
const check = (start: number, end: number): boolean => {
|
||||||
for (let i = 0; i < ranges.length; i++) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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: '',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user