diff --git a/resources/js/lib/emoji.ts b/resources/js/lib/emoji.ts index 1cc6b1bb4..f6b67bac8 100644 --- a/resources/js/lib/emoji.ts +++ b/resources/js/lib/emoji.ts @@ -16,6 +16,10 @@ const shortcodePattern = new RegExp( ); export function emojify(text: string): string { + if (!text.includes(':')) { + return text; + } + return text.replace( shortcodePattern, (_, name: string) => shortcodeEmoji[name], @@ -26,6 +30,10 @@ export function emojifyInput( text: string, caret: number, ): { text: string; caret: number } { + if (!text.includes(':')) { + return { text, caret }; + } + const emojifyTyped = (typed: string) => mapTypedProse(typed, emojify); return { diff --git a/tests/Unit/EmojiShortcodes.test.tsx b/tests/Unit/EmojiShortcodes.test.tsx index 2a42afb7d..be35742ce 100644 --- a/tests/Unit/EmojiShortcodes.test.tsx +++ b/tests/Unit/EmojiShortcodes.test.tsx @@ -26,3 +26,9 @@ test('keeps the shortcode being typed until its closing colon', () => { caret: 5, }); }); + +test('leaves plain prose untouched without shortcode processing', () => { + const text = 'shipping 🚀 without a shortcode'; + assert.equal(emojify(text), text); + assert.deepEqual(emojifyInput(text, 8), { text, caret: 8 }); +});