diff --git a/src/components/middle/composer/hooks/useEmojiTooltip.ts b/src/components/middle/composer/hooks/useEmojiTooltip.ts index fe26725f..a3978869 100644 --- a/src/components/middle/composer/hooks/useEmojiTooltip.ts +++ b/src/components/middle/composer/hooks/useEmojiTooltip.ts @@ -21,6 +21,8 @@ let RE_EMOJI_SEARCH: RegExp; const EMOJIS_LIMIT = 36; const FILTER_MIN_LENGTH = 2; const RE_BR = /(
|)/g; +const RE_SPACE = / /g; +const RE_CLEAN_HTML = /(
|<\/div>)/gi; try { RE_EMOJI_SEARCH = new RegExp('(^|\\s):[-+_:\\p{L}\\p{N}]*$', 'gui'); @@ -186,7 +188,11 @@ export default function useEmojiTooltip( } function getEmojiCode(html: string) { - const emojis = html.replace(RE_BR, '\n').replace(/\n$/i, '').match(RE_EMOJI_SEARCH); + const emojis = html + .replace(RE_SPACE, ' ') + .replace(RE_BR, '\n') + .replace(RE_CLEAN_HTML, '') + .match(RE_EMOJI_SEARCH); return emojis ? emojis[0].trim() : undefined; } diff --git a/src/components/middle/composer/hooks/useMentionTooltip.ts b/src/components/middle/composer/hooks/useMentionTooltip.ts index 00971efc..97481466 100644 --- a/src/components/middle/composer/hooks/useMentionTooltip.ts +++ b/src/components/middle/composer/hooks/useMentionTooltip.ts @@ -13,6 +13,8 @@ import { throttle } from '../../../../util/schedulers'; const runThrottled = throttle((cb) => cb(), 500, true); const RE_BR = /(
|)/g; +const RE_SPACE = / /g; +const RE_CLEAN_HTML = /(
|<\/div>)/gi; const RE_USERNAME_SEARCH = new RegExp('(^|\\s)@[\\w\\d_-]*$', 'gi'); export default function useMentionTooltip( @@ -120,7 +122,12 @@ export default function useMentionTooltip( } function getUsernameFilter(html: string) { - const username = html.replace(RE_BR, '\n').replace(/\n$/i, '').match(RE_USERNAME_SEARCH); + const username = html + .replace(RE_SPACE, ' ') + .replace(RE_BR, '\n') + .replace(RE_CLEAN_HTML, '') + .replace(/\n$/i, '') + .match(RE_USERNAME_SEARCH); return username ? username[0].trim() : undefined; }