improve getMarkAttrs when selection is empty

This commit is contained in:
Philipp Kühn 2020-11-06 14:03:51 +01:00
parent 2260f3615e
commit da1aaec025

View File

@ -5,10 +5,13 @@ export default function getMarkAttrs(state: EditorState, type: MarkType) {
const { from, to, empty } = state.selection
let marks: Mark[] = []
// TODO: -1 only for inclusive marks?
state.doc.nodesBetween(empty ? from - 1 : from, to, node => {
marks = [...marks, ...node.marks]
})
if (empty) {
marks = state.selection.$head.marks()
} else {
state.doc.nodesBetween(from, to, node => {
marks = [...marks, ...node.marks]
})
}
const mark = marks.find(markItem => markItem.type.name === type.name)