Skip to content

Commit e41e3fc

Browse files
authored
perf: skip emoji parsing in text without shortcode delimiters (#1423)
1 parent d432328 commit e41e3fc

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎resources/js/lib/emoji.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const shortcodePattern = new RegExp(
1616
);
1717

1818
export function emojify(text: string): string {
19+
if (!text.includes(':')) {
20+
return text;
21+
}
22+
1923
return text.replace(
2024
shortcodePattern,
2125
(_, name: string) => shortcodeEmoji[name],
@@ -26,6 +30,10 @@ export function emojifyInput(
2630
text: string,
2731
caret: number,
2832
): { text: string; caret: number } {
33+
if (!text.includes(':')) {
34+
return { text, caret };
35+
}
36+
2937
const emojifyTyped = (typed: string) => mapTypedProse(typed, emojify);
3038

3139
return {

‎tests/Unit/EmojiShortcodes.test.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ test('keeps the shortcode being typed until its closing colon', () => {
2626
caret: 5,
2727
});
2828
});
29+
30+
test('leaves plain prose untouched without shortcode processing', () => {
31+
const text = 'shipping 🚀 without a shortcode';
32+
assert.equal(emojify(text), text);
33+
assert.deepEqual(emojifyInput(text, 8), { text, caret: 8 });
34+
});

0 commit comments

Comments
 (0)