Merge pull request #283 from StickyKnow/fix-nodeIsActive

fix nodeIsActive()
This commit is contained in:
Philipp Kühn 2019-05-07 07:43:43 +02:00 committed by GitHub
commit 7d4ec06a87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,12 +1,16 @@
import { findParentNode } from 'prosemirror-utils' import {
findParentNode,
findSelectedNodeOfType,
} from 'prosemirror-utils'
export default function (state, type, attrs = {}) { export default function (state, type, attrs = {}) {
const predicate = node => node.type === type const predicate = node => node.type === type
const parent = findParentNode(predicate)(state.selection) const node = findSelectedNodeOfType(type)(state.selection)
|| findParentNode(predicate)(state.selection)
if (!Object.keys(attrs).length || !parent) { if (!Object.keys(attrs).length || !node) {
return !!parent return !!node
} }
return parent.node.hasMarkup(type, attrs) return node.node.hasMarkup(type, attrs)
} }