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

Function editorPointToRelativePosition

packages/yjs-transform/src/position.ts:10–26  ·  view source on GitHub ↗
(
  sharedRoot: Y.XmlText,
  editorRoot: Node,
  point: BasePoint,
)

Source from the content-addressed store, hash-verified

8export const STORED_POSITION_PREFIX = '__editorYjsStoredPosition_'
9
10export function editorPointToRelativePosition(
11 sharedRoot: Y.XmlText,
12 editorRoot: Node,
13 point: BasePoint,
14): Y.RelativePosition {
15 const { yTarget, yParent, textRange } = getYTarget(sharedRoot, editorRoot, point.path)
16
17 if (yTarget) {
18 throw new Error('Editor point points to a non-text element inside sharedRoot')
19 }
20
21 return Y.createRelativePositionFromTypeIndex(
22 yParent,
23 textRange.start + point.offset,
24 point.offset === textRange.end ? -1 : 0,
25 )
26}
27
28export function absolutePositionToEditorPoint(
29 sharedRoot: Y.XmlText,

Callers 2

storePositionFunction · 0.90

Calls 1

getYTargetFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…