(
sharedRoot: Y.XmlText,
editorRoot: Node,
{ type, index, assoc }: Y.AbsolutePosition,
)
| 26 | } |
| 27 | |
| 28 | export function absolutePositionToEditorPoint( |
| 29 | sharedRoot: Y.XmlText, |
| 30 | editorRoot: Node, |
| 31 | { type, index, assoc }: Y.AbsolutePosition, |
| 32 | ): BasePoint | null { |
| 33 | if (!(type instanceof Y.XmlText)) { |
| 34 | throw new Error('Absolute position points to a non-XMLText') |
| 35 | } |
| 36 | |
| 37 | const parentPath = getEditorPath(sharedRoot, editorRoot, type) |
| 38 | const parent = Node.get(editorRoot, parentPath) |
| 39 | |
| 40 | if (Text.isText(parent)) { |
| 41 | throw new Error("Absolute position doesn't match editorRoot, cannot descent into text") |
| 42 | } |
| 43 | |
| 44 | const [pathOffset, textOffset] = yOffsetToEditorOffsets(parent, index, { |
| 45 | assoc, |
| 46 | }) |
| 47 | |
| 48 | const target = parent.children[pathOffset] |
| 49 | if (!Text.isText(target)) { |
| 50 | return null |
| 51 | } |
| 52 | |
| 53 | return { path: [...parentPath, pathOffset], offset: textOffset } |
| 54 | } |
| 55 | |
| 56 | export function relativePositionToEditorPoint( |
| 57 | sharedRoot: Y.XmlText, |
no test coverage detected
searching dependent graphs…