diff --git a/packages/utils/package.json b/packages/utils/package.json index 46bf1ed..3be5d99 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -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/", diff --git a/packages/utils/src/emoji/replace/find.ts b/packages/utils/src/emoji/replace/find.ts index be7287b..29638c8 100644 --- a/packages/utils/src/emoji/replace/find.ts +++ b/packages/utils/src/emoji/replace/find.ts @@ -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; } } diff --git a/packages/utils/tests/emoji-regex-find-test.ts b/packages/utils/tests/emoji-regex-find-test.ts index 106bd86..4509a40 100644 --- a/packages/utils/tests/emoji-regex-find-test.ts +++ b/packages/utils/tests/emoji-regex-find-test.ts @@ -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: '', + }, + ]); + }); });