Class YText

Direct Known Subclasses:
YXmlText

public class YText extends AbstractType<YTextEvent>
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*).
  • Constructor Details

    • YText

      public YText()
      Constructs a new YText without initial string.
    • YText

      public YText(String string)
      Constructs a new YText with an optional initial string.
      Parameters:
      string - The initial value of the YText.
  • Method Details

    • getSearchMarker

      public List<ArraySearchMarker> getSearchMarker()
      Overrides:
      getSearchMarker in class AbstractType<YTextEvent>
    • setSearchMarker

      public void setSearchMarker(List<ArraySearchMarker> searchMarker)
    • isHasFormatting

      public boolean isHasFormatting()
    • setHasFormatting

      public void setHasFormatting(boolean hasFormatting)
    • length

      public int length()
      Number of characters of this text type.
      Overrides:
      length in class AbstractType<YTextEvent>
    • integrate

      public void integrate(Doc y, Item item)
      Description copied from class: AbstractType
      Integrate this type into the Yjs instance. Save this struct in the os This type is sent to other client Observer functions are fired
      Overrides:
      integrate in class AbstractType<YTextEvent>
      Parameters:
      y - The Yjs instance
      item - The item to integrate
    • copy

      public YText copy()
      Overrides:
      copy in class AbstractType<YTextEvent>
    • clone

      public YText clone()
      Description copied from class: AbstractType
      Makes 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:
      clone in class AbstractType<YTextEvent>
      Returns:
      A copy of this data type
    • callObserver

      public void callObserver(Transaction transaction, Set<String> parentSubs)
      Creates YTextEvent and calls observers.
      Overrides:
      callObserver in class AbstractType<YTextEvent>
      Parameters:
      transaction - The current transaction
      parentSubs - Keys changed on this type. `null` if list was modified.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toJSON

      public String toJSON()
      Description copied from class: AbstractType
      Converts the type to a JSON object representation.
      Overrides:
      toJSON in class AbstractType<YTextEvent>
      Returns:
      The JSON object representation
    • applyDelta

      public void applyDelta(List<Map<String,Object>> deltasMap)
    • applyDelta

      public void applyDelta(List<Map<String,Object>> deltasMap, boolean sanitize)
    • toDeltaMap

      public List<Map<String,Object>> toDeltaMap()
    • toDeltaMap

      public List<Map<String,Object>> toDeltaMap(Snapshot snapshot, Snapshot prevSnapshot, BiFunction<String,ID,Object> computeYChange)
    • toDeltaList

      public List<Delta> toDeltaList()
    • toDeltaList

      public List<Delta> toDeltaList(Snapshot snapshot, Snapshot prevSnapshot, BiFunction<String,ID,Object> computeYChange)
    • insert

      public void insert(int index, String text)
    • insert

      public void insert(int index, String text, Map<String,Object> attributes)
    • insertEmbed

      public void insertEmbed(int index, Object embed)
    • insertEmbed

      public void insertEmbed(int index, Object embed, Map<String,Object> attributes)
    • delete

      public void delete(int index)
    • delete

      public void delete(int index, int length)
    • format

      public void format(int index, int length, Map<String,Object> attributes)
    • removeAttribute

      public void removeAttribute(String attributeName)
    • setAttribute

      public void setAttribute(String attributeName, Object attributeValue)
    • getAttribute

      public Object getAttribute(String attributeName)
    • getAttributes

      public Map<String,Object> getAttributes()
    • write

      public void write(UpdateEncoder encoder)
      Description copied from class: AbstractType
      Writes this type's state to the encoder.
      Overrides:
      write in class AbstractType<YTextEvent>
      Parameters:
      encoder - The encoder to write to
    • equalAttrs

      public static boolean equalAttrs(Object a, Object b)
      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

      public static int cleanupYTextFormatting(YText type)
      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

      public static void cleanupYTextAfterTransaction(Transaction transaction)
      Cleans up YText formatting after a transaction.
      Parameters:
      transaction - The current transaction.
    • readYText

      public static YText readYText(UpdateDecoder decoder)
      Reads and returns a new YText instance from the decoder.
      Parameters:
      decoder - The decoder to read from.
      Returns:
      A new YText instance.