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) +}