"a|c"
, the relative position is attached to c
. When a remote user modifies the document by inserting a character before the cursor, the cursor will stay attached to the character c
. insert(1, 'x')("a|c") = "ax|c"
. When the relative position is set to the end of the document, it will stay attached to the end of the document.Y.createRelativePositionFromTypeIndex(type: Y.AbstractType, index: number [, assoc=0]): Y.RelativePosition
Create a relative position fixated to the i-th element in any sequence-like shared type (if assoc >= 0
). By default, the position associates with the character that comes after the specified index position. If assoc < 0
, then the relative position associates with the character before the specified index position. Y.createAbsolutePositionFromRelativePosition(Y.RelativePosition, Y.Doc): { type: Y.AbstractType, index: number, assoc: number } | null
Create an absolute position from a relative position. If the relative position cannot be referenced, or the type is deleted, then the result is null.Y.encodeRelativePosition(Y.RelativePosition): Uint8Array
Encode a relative position to an Uint8Array. Binary data is the preferred encoding format for document updates. If you prefer JSON encoding, you can simply JSON.stringify
/ JSON.parse
the relative position instead.Y.decodeRelativePosition(Uint8Array): RelativePosition
Decode a binary-encoded relative position to a RelativePositon object.