From 5a1a5c7c1a9107ae582739f822b57f2c4fb7c01e Mon Sep 17 00:00:00 2001 From: fantasticit Date: Mon, 28 Nov 2022 23:00:58 +0800 Subject: [PATCH] improve get fontSize --- .../client/src/tiptap/core/menus/fontsize/index.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/client/src/tiptap/core/menus/fontsize/index.tsx b/packages/client/src/tiptap/core/menus/fontsize/index.tsx index 7facc5fd..7fbba35f 100644 --- a/packages/client/src/tiptap/core/menus/fontsize/index.tsx +++ b/packages/client/src/tiptap/core/menus/fontsize/index.tsx @@ -9,9 +9,14 @@ export const FONT_SIZES = [12, 13, 14, 15, 16, 19, 22, 24, 29, 32, 40, 48]; export const FontSize: React.FC<{ editor: Editor }> = ({ editor }) => { const isTitleActive = useActive(editor, Title.name); - const currentFontSize = useAttributes(editor, 'textStyle', { fontSize: '16px' }, (attrs) => - attrs.fontSize.replace('px', '') - ); + const currentFontSize = useAttributes(editor, 'textStyle', { fontSize: '16px' }, (attrs) => { + if (!attrs || !attrs.fontSize) return 16; + + const matches = attrs.fontSize.match(/\d+/); + + if (!matches || !matches[0]) return 16; + return matches[0]; + }); const toggle = useCallback( (val) => {