fix: emoji replacement error handling

zio/stable
Anthony Fu 2022-12-27 21:48:01 +01:00
parent dc94d707b0
commit 2d2dc64efc
1 changed files with 22 additions and 11 deletions

View File

@ -49,8 +49,7 @@ export const Emoji = Node.create({
},
addInputRules() {
return [
nodeInputRule({
const inputRule = nodeInputRule({
find: EMOJI_REGEX,
type: this.type,
getAttributes: (match) => {
@ -60,7 +59,19 @@ export const Emoji = Node.create({
fallback: native,
}
},
}),
})
// Error catch for unsupported emoji
const handler = inputRule.handler.bind(inputRule)
inputRule.handler = (...args) => {
try {
return handler(...args)
}
catch (e) {
return null
}
}
return [
inputRule,
]
},
})