fix: improve isActive check for floating menu when using custom doc content, fix #1205

This commit is contained in:
Philipp Kühn 2021-04-23 23:01:53 +02:00
parent cd595b8ece
commit b84a56a84a

View File

@ -1,4 +1,4 @@
import { Editor, isNodeEmpty, posToDOMRect } from '@tiptap/core'
import { Editor, posToDOMRect } from '@tiptap/core'
import { EditorState, Plugin, PluginKey } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import tippy, { Instance, Props } from 'tippy.js'
@ -95,9 +95,8 @@ export class FloatingMenuView {
to,
} = selection
const isRootDepth = $anchor.depth === 1
const isDefaultNodeType = $anchor.parent.type === state.doc.type.contentMatch.defaultType
const isDefaultNodeEmpty = isNodeEmpty(selection.$anchor.parent)
const isActive = isRootDepth && isDefaultNodeType && isDefaultNodeEmpty
const isNodeEmpty = !selection.$anchor.parent.isLeaf && !selection.$anchor.parent.textContent
const isActive = isRootDepth && isNodeEmpty
if (!empty || !isActive) {
this.hide()