a tool for shared writing and social publishing
1import { schema } from "components/Blocks/TextBlock/schema";
2import { Mark, MarkType } from "prosemirror-model";
3import { EditorState } from "prosemirror-state";
4
5export function rangeHasMark(
6 state: EditorState,
7 type: MarkType,
8 start: number,
9 end: number,
10) {
11 let mark: Mark | null = null;
12 let length = end - start;
13 if (!type.spec.inclusive) length = length - 1;
14 for (let i = 1; i <= length; i++) {
15 let pos = state.doc.resolve(start + i);
16 let markAtPos = pos.marks().find((f) => f.type === type);
17 if (!mark) {
18 if (!markAtPos) {
19 return null;
20 }
21 mark = markAtPos;
22 } else {
23 if (!markAtPos) return null;
24 if (mark !== markAtPos) {
25 return null;
26 }
27 }
28 }
29 return mark;
30}