mirror of
https://github.com/danog/telegram-tt.git
synced 2024-11-26 20:34:44 +01:00
Composer: Fix Emoji and Mention tooltips sometimes missing (#1353)
This commit is contained in:
parent
92a3d8126a
commit
edb18236b3
@ -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 = / /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;
|
||||
}
|
||||
|
@ -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 = / /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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user