mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-23 08:47:50 +08:00
23 lines
508 B
TypeScript
23 lines
508 B
TypeScript
|
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
|
||
|
}
|