fix(core): correct emoji extraction logic using regex (#12749)

https://github.com/user-attachments/assets/ef612f34-0388-49a2-bcad-0cac07a5f785

This PR solves the issue where a majority of emoji's are unable to
become the document or folders icon.

The regex used is below with the test string of a variety of emoji's:
https://regex101.com/r/0anB6Z/1

Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com>
This commit is contained in:
Richard Lora
2025-09-21 10:43:46 -04:00
committed by GitHub
parent 19bd29e90c
commit 4efbb630fc
2 changed files with 23 additions and 5 deletions

View File

@@ -9,7 +9,22 @@ test('extract-emoji-icon', () => {
});
expect(extractEmojiIcon('❤123')).toEqual({
emoji: '❤️',
rest: '123',
});
expect(extractEmojiIcon('➡456')).toEqual({
emoji: '➡️',
rest: '456',
});
expect(extractEmojiIcon('✈789')).toEqual({
emoji: '✈️',
rest: '789',
});
expect(extractEmojiIcon('plain text')).toEqual({
emoji: null,
rest: '123',
rest: 'plain text',
});
});

View File

@@ -1,13 +1,16 @@
import Graphemer from 'graphemer';
const emojiRe =
/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g;
export function extractEmojiIcon(text: string) {
const isStartsWithEmoji = /^(\p{Emoji_Presentation})/u.test(text);
if (isStartsWithEmoji) {
emojiRe.lastIndex = 0;
const match = emojiRe.exec(text);
if (match && match.index === 0) {
// emoji like "👨🏻‍❤️‍💋‍👨🏻" are combined. Graphemer can handle these.
const emojiEnd = Graphemer.nextBreak(text, 0);
return {
emoji: text.substring(0, emojiEnd),
rest: text.substring(emojiEnd),
emoji: text.slice(0, emojiEnd),
rest: text.slice(emojiEnd),
};
}
return {