2020-03-30 06:20:38 +08:00
|
|
|
import { EditorState } from 'prosemirror-state'
|
|
|
|
import { MarkType } from 'prosemirror-model'
|
2020-10-05 23:12:57 +08:00
|
|
|
import markHasAttributes from './markHasAttributes'
|
2020-03-30 06:20:38 +08:00
|
|
|
|
2020-10-05 23:12:57 +08:00
|
|
|
export default function markIsActive(state: EditorState, type: MarkType, attrs?: {}) {
|
2020-03-30 06:20:38 +08:00
|
|
|
const {
|
|
|
|
from,
|
|
|
|
$from,
|
|
|
|
to,
|
|
|
|
empty,
|
|
|
|
} = state.selection
|
|
|
|
|
2020-10-05 23:12:57 +08:00
|
|
|
const hasAttributes = markHasAttributes(state, type, attrs)
|
|
|
|
|
2020-03-30 06:20:38 +08:00
|
|
|
if (empty) {
|
2020-10-05 23:12:57 +08:00
|
|
|
return (type.isInSet(state.storedMarks || $from.marks()) && hasAttributes)
|
2020-03-30 06:20:38 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 23:12:57 +08:00
|
|
|
return (state.doc.rangeHasMark(from, to, type) && hasAttributes)
|
2020-03-30 06:20:38 +08:00
|
|
|
}
|