Skip to content

Commit

Permalink
UBER-987: Fix emojis in the middle of something (URLs) (#3790)
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Karmatskikh <mkarmatskih@gmail.com>
  • Loading branch information
mixerka authored Oct 5, 2023
1 parent 3ca2fcc commit 4a201db
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions packages/text-editor/src/components/extension/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const emojiReplaceDict = {
":'-)": '😂',
':)': '😊',
':-)': '😄',
':]': '😄',
':^)': '😄',
':o)': '😄',
':}': '😄',
Expand All @@ -28,27 +27,19 @@ const emojiReplaceDict = {
';)': '😉',
';-)': '😉',
';-]': '😉',
';]': '😉',
';^)': '😉',
':-|': '😐',
':|': '😐',
':(': '😞',
':-(': '😒',
':-<': '😒',
':-[': '😒',
':-c': '😒',
':<': '😒',
':[': '😒',
':{': '😒',
'%)': '😖',
'%-)': '😖',
':-P': '😜',
':-p': '😜',
';(': '😜',
':-||': '😠',
':-.': '😡',
':-/': '😡',
':/': '😐',
":'(": '😢',
":'-(": '😢',
':-O': '😲',
Expand All @@ -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]
Expand Down

0 comments on commit 4a201db

Please sign in to comment.