From 210adf583bb693793ae3340229a8ed6dc540742c Mon Sep 17 00:00:00 2001 From: fantasticit Date: Mon, 28 Nov 2022 23:00:22 +0800 Subject: [PATCH] improve text-bubble-menu --- packages/client/src/tiptap/core/menus/text/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/client/src/tiptap/core/menus/text/index.tsx b/packages/client/src/tiptap/core/menus/text/index.tsx index c7335af7..bc4fd16d 100644 --- a/packages/client/src/tiptap/core/menus/text/index.tsx +++ b/packages/client/src/tiptap/core/menus/text/index.tsx @@ -33,7 +33,6 @@ import { Underline } from '../underline'; const OTHER_BUBBLE_MENU_TYPES = [ Title.name, - Link.name, Attachment.name, Countdown.name, Image.name, @@ -55,7 +54,14 @@ const OTHER_BUBBLE_MENU_TYPES = [ export const Text = ({ editor }) => { const shouldShow = useCallback(() => { - return !editor.state.selection.empty && OTHER_BUBBLE_MENU_TYPES.every((type) => !editor.isActive(type)); + if (editor.state.selection.empty) return false; + if (OTHER_BUBBLE_MENU_TYPES.some((type) => editor.isActive(type))) return false; + + const selection = editor.state.selection; + const slice = selection.content(); + const text = slice.content.textBetween(0, slice.content.size); + + return text && text.length; }, [editor]); return (