MCPcopy Create free account
hub / github.com/editablejs/editable / absolutePositionToEditorPoint

Function absolutePositionToEditorPoint

packages/yjs-transform/src/position.ts:28–54  ·  view source on GitHub ↗
(
  sharedRoot: Y.XmlText,
  editorRoot: Node,
  { type, index, assoc }: Y.AbsolutePosition,
)

Source from the content-addressed store, hash-verified

26}
27
28export 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
56export function relativePositionToEditorPoint(
57 sharedRoot: Y.XmlText,

Callers 1

Calls 3

getEditorPathFunction · 0.90
yOffsetToEditorOffsetsFunction · 0.90
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…