Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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