From b26bb4b276741321776747d31aacc5b7cf03f426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Mon, 30 Mar 2020 00:20:38 +0200 Subject: [PATCH] add markIsActive --- packages/tiptap-core/src/utils/markIsActive.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 packages/tiptap-core/src/utils/markIsActive.ts diff --git a/packages/tiptap-core/src/utils/markIsActive.ts b/packages/tiptap-core/src/utils/markIsActive.ts new file mode 100644 index 00000000..e8be9511 --- /dev/null +++ b/packages/tiptap-core/src/utils/markIsActive.ts @@ -0,0 +1,17 @@ +import { EditorState } from 'prosemirror-state' +import { MarkType } from 'prosemirror-model' + +export default function markIsActive(state: EditorState, type: MarkType) { + const { + from, + $from, + to, + empty, + } = state.selection + + if (empty) { + return !!type.isInSet(state.storedMarks || $from.marks()) + } + + return !!state.doc.rangeHasMark(from, to, type) +}