Package io.keikai.doc.collab.utils
Class RelativePosition
java.lang.Object
io.keikai.doc.collab.utils.RelativePosition
A relative position is based on the Yjs model and is not affected by document changes.
E.g. If you place a relative position before a certain character, it will always point to this character.
If you place a relative position at the end of a type, it will always point to the end of the type.
A numeric position is often unsuited for user selections, because it does not change when content is inserted
before or after.
```Insert(0, 'x')('a|bc') = 'xa|bc'``` Where | is the relative position.
One of the properties must be defined.
-
Constructor Summary
ConstructorsConstructorDescriptionRelativePosition(ID type, String typeName, ID item) Constructor for RelativePosition with default association value.RelativePosition(ID type, String tname, ID item, int assoc) Constructor for RelativePosition. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCompare two RelativePositions.static AbsolutePositioncreateAbsolutePosition(AbstractType type, int index, int assoc) Create an AbsolutePosition.static AbsolutePositionTransform a relative position to an absolute position, and follow undone deletions.static AbsolutePositioncreateAbsolutePositionFromRelativePosition(RelativePosition rpos, Doc doc, boolean followUndoneDeletions) Transform a relative position to an absolute position.static RelativePositioncreateRelativePosition(AbstractType type, ID item, int assoc) Create a RelativePosition from an AbstractType and an item ID.static RelativePositionCreate a RelativePosition from a JSON-like structure.static RelativePositioncreateRelativePositionFromTypeIndex(AbstractType type, int index) Create a RelativePosition based on an absolute position.static RelativePositioncreateRelativePositionFromTypeIndex(AbstractType type, int index, int assoc) Create a RelativePosition based on an absolute position.static RelativePositiondecodeRelativePosition(Uint8Array uint8Array) Decode a RelativePosition from a byte array.static Uint8ArrayEncode a RelativePosition to a byte array.getAssoc()getItem()getType()static RelativePositionreadRelativePosition(Decoder decoder) Read a RelativePosition from a decoder.Convert a RelativePosition to a JSON-like structure.static voidwriteRelativePosition(Encoder encoder, RelativePosition rpos) Write a RelativePosition to an encoder.
-
Constructor Details
-
RelativePosition
Constructor for RelativePosition.- Parameters:
type- The ID of the type, or null if not applicable.tname- The name of the type, or null if not applicable.item- The ID of the item, or null if not applicable.assoc- The association value, defaults to 0 if not provided.
-
RelativePosition
Constructor for RelativePosition with default association value.- Parameters:
type- The ID of the type, or null if not applicable.typeName- The name of the type, or null if not applicable.item- The ID of the item, or null if not applicable.
-
-
Method Details
-
getType
-
getTypeName
-
getItem
-
getAssoc
-
relativePositionToJSON
Convert a RelativePosition to a JSON-like structure.- Parameters:
rpos- The RelativePosition to convert.- Returns:
- A Map representing the JSON-like structure.
-
createRelativePositionFromJSON
Create a RelativePosition from a JSON-like structure.- Parameters:
json- The JSON-like structure.- Returns:
- A new RelativePosition instance.
-
createAbsolutePosition
Create an AbsolutePosition.- Parameters:
type- The base type (e.g., YText or YArray).index- The absolute position.assoc- The association value (optional).- Returns:
- A new AbsolutePosition instance.
-
createRelativePosition
Create a RelativePosition from an AbstractType and an item ID.- Parameters:
type- The base type (e.g., YText or YArray).item- The ID of the item.assoc- The association value (optional).- Returns:
- A new RelativePosition instance.
-
createRelativePositionFromTypeIndex
Create a RelativePosition based on an absolute position.- Parameters:
type- The base type (e.g., YText or YArray).index- The absolute position.- Returns:
- A new RelativePosition instance.
-
createRelativePositionFromTypeIndex
public static RelativePosition createRelativePositionFromTypeIndex(AbstractType type, int index, int assoc) Create a RelativePosition based on an absolute position.- Parameters:
type- The base type (e.g., YText or YArray).index- The absolute position.assoc- The association value (optional).- Returns:
- A new RelativePosition instance.
-
writeRelativePosition
Write a RelativePosition to an encoder.- Parameters:
encoder- The encoder to write to.rpos- The RelativePosition to write.
-
encodeRelativePosition
Encode a RelativePosition to a byte array.- Parameters:
rpos- The RelativePosition to encode.- Returns:
- The encoded Uint8Array.
-
readRelativePosition
Read a RelativePosition from a decoder.- Parameters:
decoder- The decoder to read from.- Returns:
- The decoded RelativePosition.
-
decodeRelativePosition
Decode a RelativePosition from a byte array.- Parameters:
uint8Array- The byte array to decode.- Returns:
- The decoded RelativePosition.
-
createAbsolutePositionFromRelativePosition
public static AbsolutePosition createAbsolutePositionFromRelativePosition(RelativePosition rpos, Doc doc) Transform a relative position to an absolute position, and follow undone deletions.- Parameters:
rpos- The relative position.doc- The document.- Returns:
- The absolute position, or null if not found.
-
createAbsolutePositionFromRelativePosition
public static AbsolutePosition createAbsolutePositionFromRelativePosition(RelativePosition rpos, Doc doc, boolean followUndoneDeletions) Transform a relative position to an absolute position.- Parameters:
rpos- The relative position.doc- The document.followUndoneDeletions- Whether to follow undone deletions.- Returns:
- The absolute position, or null if not found.
-
compareRelativePositions
Compare two RelativePositions.- Parameters:
a- The first RelativePosition.b- The second RelativePosition.- Returns:
- True if they are equal, false otherwise.
-