From ab5a7d4dbf10cc48511bfd6049a52237dff8f4ce Mon Sep 17 00:00:00 2001 From: David Newell Date: Thu, 5 Oct 2023 11:56:37 +0100 Subject: [PATCH] fix: hide bubble menu for non text blocks (#17796) --- .../src/scenes/notebooks/Notebook/InlineMenu.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/frontend/src/scenes/notebooks/Notebook/InlineMenu.tsx b/frontend/src/scenes/notebooks/Notebook/InlineMenu.tsx index 7a2e837c16853..e834c5771b277 100644 --- a/frontend/src/scenes/notebooks/Notebook/InlineMenu.tsx +++ b/frontend/src/scenes/notebooks/Notebook/InlineMenu.tsx @@ -1,5 +1,5 @@ import { LemonButton, LemonInput } from '@posthog/lemon-ui' -import { Editor } from '@tiptap/core' +import { Editor, isTextSelection } from '@tiptap/core' import { BubbleMenu } from '@tiptap/react' import { IconBold, IconDelete, IconItalic, IconLink, IconOpenInNew } from 'lib/lemon-ui/icons' @@ -15,7 +15,19 @@ export const InlineMenu = ({ editor }: { editor: Editor }): JSX.Element => { } return ( - + { + const hasEditorFocus = view.hasFocus() + const isTextBlock = isTextSelection(state.selection) + + if (!hasEditorFocus || !editor.isEditable || !isTextBlock) { + return false + } + + return state.doc.textBetween(from, to).length > 0 + }} + >
{editor.isActive('link') ? ( <>