Composer: Fix Emoji and Mention tooltips sometimes missing (#1353)

This commit is contained in:
Alexander Zinchuk 2021-08-03 19:03:26 +03:00
parent 92a3d8126a
commit edb18236b3
2 changed files with 15 additions and 2 deletions

View File

@ -21,6 +21,8 @@ let RE_EMOJI_SEARCH: RegExp;
const EMOJIS_LIMIT = 36;
const FILTER_MIN_LENGTH = 2;
const RE_BR = /(<br>|<br\s?\/>)/g;
const RE_SPACE = /&nbsp;/g;
const RE_CLEAN_HTML = /(<div>|<\/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;
}

View File

@ -13,6 +13,8 @@ import { throttle } from '../../../../util/schedulers';
const runThrottled = throttle((cb) => cb(), 500, true);
const RE_BR = /(<br>|<br\s?\/>)/g;
const RE_SPACE = /&nbsp;/g;
const RE_CLEAN_HTML = /(<div>|<\/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;
}