From 2d2dc64efc0e9223421384e3c8142f7f056ef9b6 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 27 Dec 2022 21:48:01 +0100 Subject: [PATCH] fix: emoji replacement error handling --- composables/tiptap/emoji.ts | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/composables/tiptap/emoji.ts b/composables/tiptap/emoji.ts index c0f7be3f..a658a342 100644 --- a/composables/tiptap/emoji.ts +++ b/composables/tiptap/emoji.ts @@ -49,18 +49,29 @@ export const Emoji = Node.create({ }, addInputRules() { + const inputRule = nodeInputRule({ + find: EMOJI_REGEX, + type: this.type, + getAttributes: (match) => { + const [native] = match + return { + native, + 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 [ - nodeInputRule({ - find: EMOJI_REGEX, - type: this.type, - getAttributes: (match) => { - const [native] = match - return { - native, - fallback: native, - } - }, - }), + inputRule, ] }, })