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

17 lines
414 B
TypeScript
Raw Normal View History

2021-01-28 16:50:17 +08:00
import { EditorState } from 'prosemirror-state'
2021-01-28 16:57:20 +08:00
import { MarkRange } from '../types'
2021-01-28 16:50:17 +08:00
2021-01-28 16:57:20 +08:00
export default function getMarksBetween(from: number, to: number, state: EditorState): MarkRange[] {
let marks: MarkRange[] = []
2021-01-28 16:50:17 +08:00
2021-01-28 16:57:20 +08:00
state.doc.nodesBetween(from, to, (node, pos) => {
2021-01-28 16:50:17 +08:00
marks = [...marks, ...node.marks.map(mark => ({
2021-01-28 16:57:20 +08:00
from: pos,
to: pos + node.nodeSize,
2021-01-28 16:50:17 +08:00
mark,
}))]
})
return marks
}