tiptap/packages/core/src/helpers/getMarksBetween.ts

23 lines
508 B
TypeScript
Raw Normal View History

2021-01-28 16:50:17 +08:00
import { Mark } from 'prosemirror-model'
import { EditorState } from 'prosemirror-state'
export type MarkPosition = {
mark: Mark,
start: number,
end: number,
}
export default function getMarksBetween(start: number, end: number, state: EditorState): MarkPosition[] {
let marks: MarkPosition[] = []
state.doc.nodesBetween(start, end, (node, pos) => {
marks = [...marks, ...node.marks.map(mark => ({
start: pos,
end: pos + node.nodeSize,
mark,
}))]
})
return marks
}