improve getMarkAttrs when selection is empty
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user