From f12b1273f24984806394e3deb431823a9d00ba79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 15 Jun 2021 19:06:26 +0200 Subject: [PATCH] fix: fix a bug where bubble menu does not appear when selection starts from empty paragraph node, fix #1474 --- .../extension-bubble-menu/src/bubble-menu-plugin.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/extension-bubble-menu/src/bubble-menu-plugin.ts b/packages/extension-bubble-menu/src/bubble-menu-plugin.ts index 06791f30..71cee1c2 100644 --- a/packages/extension-bubble-menu/src/bubble-menu-plugin.ts +++ b/packages/extension-bubble-menu/src/bubble-menu-plugin.ts @@ -1,4 +1,9 @@ -import { Editor, posToDOMRect, isNodeSelection } from '@tiptap/core' +import { + Editor, + posToDOMRect, + isTextSelection, + isNodeSelection, +} from '@tiptap/core' import { EditorState, Plugin, PluginKey } from 'prosemirror-state' import { EditorView } from 'prosemirror-view' import tippy, { Instance, Props } from 'tippy.js' @@ -93,7 +98,7 @@ export class BubbleMenuView { return } - const { empty, $anchor, ranges } = selection + const { empty, ranges } = selection // support for CellSelections const from = Math.min(...ranges.map(range => range.$from.pos)) @@ -102,8 +107,8 @@ export class BubbleMenuView { // Sometime check for `empty` is not enough. // Doubleclick an empty paragraph returns a node size of 2. // So we check also for an empty text size. - const { parent } = $anchor - const isEmptyTextBlock = parent.type.isTextblock && !parent.textContent + const isEmptyTextBlock = !doc.textBetween(from, to).length + && isTextSelection(view.state.selection) if (empty || isEmptyTextBlock) { this.hide()