improve types

This commit is contained in:
Philipp Kühn
2021-01-28 09:50:17 +01:00
parent a9c14fbddd
commit 4407d9a3d1
20 changed files with 58 additions and 47 deletions

View File

@@ -0,0 +1,22 @@
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
}