UBER-987: Fix emojis in the middle of something (URLs) (#3790)

Signed-off-by: Maxim Karmatskikh <mkarmatskih@gmail.com>
This commit is contained in:
Maksim Karmatskikh 2023-10-05 15:54:22 +06:00 committed by GitHub
parent 3ca2fcce44
commit 4a201db844
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,7 +19,6 @@ const emojiReplaceDict = {
":'-)": '😂',
':)': '😊',
':-)': '😄',
':]': '😄',
':^)': '😄',
':o)': '😄',
':}': '😄',
@ -28,19 +27,12 @@ const emojiReplaceDict = {
';)': '😉',
';-)': '😉',
';-]': '😉',
';]': '😉',
';^)': '😉',
':-|': '😐',
':|': '😐',
':(': '😞',
':-(': '😒',
':-<': '😒',
':-[': '😒',
':-c': '😒',
':<': '😒',
':[': '😒',
':{': '😒',
'%)': '😖',
'%-)': '😖',
':-P': '😜',
':-p': '😜',
@ -48,7 +40,6 @@ const emojiReplaceDict = {
':-||': '😠',
':-.': '😡',
':-/': '😡',
':/': '😐',
":'(": '😢',
":'-(": '😢',
':-O': '😲',
@ -58,16 +49,20 @@ const emojiReplaceDict = {
}
function escapeRegExp (text: string): string {
return text.replace(/[[\]{}()*+?.\\^$|#]/g, '\\$&')
return text.replace(/[:[\]{}()*+?.\\^$|#]/g, '\\$&')
}
export const EmojiExtension = Extension.create({
addInputRules () {
return Object.keys(emojiReplaceDict).map((pattern) => {
return {
find: new RegExp(escapeRegExp(pattern)),
find: new RegExp(`(?:^|\\s)(${escapeRegExp(pattern)})`),
handler: ({ range, match, commands }) => {
commands.insertContentAt(range, [
let replaceRange = range
if (match[0] !== match[1]) {
replaceRange = { from: range.from + 1, to: range.to }
}
commands.insertContentAt(replaceRange, [
{
type: 'text',
text: emojiReplaceDict[pattern as keyof typeof emojiReplaceDict]