From b2ec2d66e1d8d33a4fc27c60b3261a0048bc2814 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Sat, 4 May 2019 02:07:22 +0200 Subject: [PATCH] fix nodeIsActive() this fixes isActive.image() mentioned in #225 nodeIsActive was only checking parent nodes and missed the node currently selected. --- packages/tiptap-utils/src/utils/nodeIsActive.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/tiptap-utils/src/utils/nodeIsActive.js b/packages/tiptap-utils/src/utils/nodeIsActive.js index 53f2037cc..2dbfdb718 100644 --- a/packages/tiptap-utils/src/utils/nodeIsActive.js +++ b/packages/tiptap-utils/src/utils/nodeIsActive.js @@ -1,12 +1,16 @@ -import { findParentNode } from 'prosemirror-utils' +import { + findParentNode, + findSelectedNodeOfType, +} from 'prosemirror-utils' export default function (state, type, attrs = {}) { 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) { - return !!parent + if (!Object.keys(attrs).length || !node) { + return !!node } - return parent.node.hasMarkup(type, attrs) + return node.node.hasMarkup(type, attrs) }