Package io.keikai.doc.collab.types
Class YText
- Direct Known Subclasses:
YXmlText
Type that represents text with formatting information.
This type replaces y-richtext as this implementation is able to handle
block formats (format information on a paragraph), embeds (complex elements
like pictures and videos), and text formats (**bold**, *italic*).
-
Field Summary
Fields inherited from class io.keikai.doc.collab.types.AbstractType
_doc, _length, _map, _searchMarker -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyDelta(List<Map<String, Object>> deltasMap) voidapplyDelta(List<Map<String, Object>> deltasMap, boolean sanitize) voidcallObserver(Transaction transaction, Set<String> parentSubs) Creates YTextEvent and calls observers.static voidcleanupYTextAfterTransaction(Transaction transaction) Cleans up YText formatting after a transaction.static intcleanupYTextFormatting(YText type) Cleans up unnecessary formatting attributes in the YText type.clone()Makes a copy of this data type that can be included somewhere else.copy()voiddelete(int index) voiddelete(int index, int length) static booleanequalAttrs(Object a, Object b) Compare two attributes for equality.static ItemTextListPositionfindNextPosition(Transaction transaction, ItemTextListPosition pos, int count) voidgetAttribute(String attributeName) voidvoidvoidinsertEmbed(int index, Object embed) voidinsertEmbed(int index, Object embed, Map<String, Object> attributes) static voidinsertNegatedAttributes(Transaction transaction, AbstractType parent, ItemTextListPosition currPos, Map<String, Object> negatedAttributes) voidIntegrate this type into the Yjs instance.booleanintlength()Number of characters of this text type.static YTextreadYText(UpdateDecoder decoder) Reads and returns a new YText instance from the decoder.voidremoveAttribute(String attributeName) voidsetAttribute(String attributeName, Object attributeValue) voidsetHasFormatting(boolean hasFormatting) voidsetSearchMarker(List<ArraySearchMarker> searchMarker) toDeltaList(Snapshot snapshot, Snapshot prevSnapshot, BiFunction<String, ID, Object> computeYChange) toDeltaMap(Snapshot snapshot, Snapshot prevSnapshot, BiFunction<String, ID, Object> computeYChange) toJSON()Converts the type to a JSON object representation.toString()voidwrite(UpdateEncoder encoder) Writes this type's state to the encoder.Methods inherited from class io.keikai.doc.collab.types.AbstractType
callTypeObservers, createMapIterator, getDeepEventHandler, getDoc, getFirst, getItem, getMap, getParent, getStart, getTypeChildren, isParentOf, observe, observe, observeDeep, setLength, setMap, setStart, typeListCreateIterator, typeListDelete, typeListForEach, typeListForEachSnapshot, typeListGet, typeListInsertGenerics, typeListInsertGenericsAfter, typeListMap, typeListPushGenerics, typeListSlice, typeListToArray, typeListToArraySnapshot, typeMapDelete, typeMapGet, typeMapGetAll, typeMapGetAllSnapshot, typeMapGetSnapshot, typeMapHas, typeMapSet, unobserve, unobserveDeep
-
Constructor Details
-
YText
public YText()Constructs a new YText without initial string. -
YText
Constructs a new YText with an optional initial string.- Parameters:
string- The initial value of the YText.
-
-
Method Details
-
getSearchMarker
- Overrides:
getSearchMarkerin classAbstractType<YTextEvent>
-
setSearchMarker
-
isHasFormatting
public boolean isHasFormatting() -
setHasFormatting
public void setHasFormatting(boolean hasFormatting) -
length
public int length()Number of characters of this text type.- Overrides:
lengthin classAbstractType<YTextEvent>
-
integrate
Description copied from class:AbstractTypeIntegrate this type into the Yjs instance. Save this struct in the os This type is sent to other client Observer functions are fired- Overrides:
integratein classAbstractType<YTextEvent>- Parameters:
y- The Yjs instanceitem- The item to integrate
-
copy
- Overrides:
copyin classAbstractType<YTextEvent>
-
clone
Description copied from class:AbstractTypeMakes a copy of this data type that can be included somewhere else. Note that the content is only readable _after_ it has been included somewhere in the Ydoc.- Overrides:
clonein classAbstractType<YTextEvent>- Returns:
- A copy of this data type
-
callObserver
Creates YTextEvent and calls observers.- Overrides:
callObserverin classAbstractType<YTextEvent>- Parameters:
transaction- The current transactionparentSubs- Keys changed on this type. `null` if list was modified.
-
toString
-
toJSON
Description copied from class:AbstractTypeConverts the type to a JSON object representation.- Overrides:
toJSONin classAbstractType<YTextEvent>- Returns:
- The JSON object representation
-
applyDelta
-
applyDelta
-
toDeltaMap
-
toDeltaMap
-
toDeltaList
-
toDeltaList
-
insert
-
insert
-
insertEmbed
-
insertEmbed
-
delete
public void delete(int index) -
delete
public void delete(int index, int length) -
format
-
removeAttribute
-
setAttribute
-
getAttribute
-
getAttributes
-
write
Description copied from class:AbstractTypeWrites this type's state to the encoder.- Overrides:
writein classAbstractType<YTextEvent>- Parameters:
encoder- The encoder to write to
-
equalAttrs
Compare two attributes for equality.- Parameters:
a- The first attribute.b- The second attribute.- Returns:
- True if the attributes are equal, false otherwise.
-
findNextPosition
public static ItemTextListPosition findNextPosition(Transaction transaction, ItemTextListPosition pos, int count) - Parameters:
transaction- The transaction in which this operation is happening.pos- The current position in the text list.count- The number of steps to move forward.- Returns:
- The updated position.
-
insertNegatedAttributes
public static void insertNegatedAttributes(Transaction transaction, AbstractType parent, ItemTextListPosition currPos, Map<String, Object> negatedAttributes) - Parameters:
transaction- The current transaction.parent- The parent type.currPos- The current position in the text list.negatedAttributes- The attributes to be negated.
-
cleanupYTextFormatting
Cleans up unnecessary formatting attributes in the YText type.- Parameters:
type- The YText type to clean up.- Returns:
- The number of formatting attributes cleaned up.
-
cleanupYTextAfterTransaction
Cleans up YText formatting after a transaction.- Parameters:
transaction- The current transaction.
-
readYText
Reads and returns a new YText instance from the decoder.- Parameters:
decoder- The decoder to read from.- Returns:
- A new YText instance.
-