tiptap/packages/core/src/helpers/getMarksBetween.ts
Philipp Kühn 6a5dde0101 refactoring
2021-01-28 09:57:20 +01:00

17 lines
414 B
TypeScript

import { EditorState } from 'prosemirror-state'
import { MarkRange } from '../types'
export default function getMarksBetween(from: number, to: number, state: EditorState): MarkRange[] {
let marks: MarkRange[] = []
state.doc.nodesBetween(from, to, (node, pos) => {
marks = [...marks, ...node.marks.map(mark => ({
from: pos,
to: pos + node.nodeSize,
mark,
}))]
})
return marks
}