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 Detail

      • YText

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

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

      • setSearchMarker

        public void setSearchMarker​(java.util.List<ArraySearchMarker> searchMarker)
      • isHasFormatting

        public boolean isHasFormatting()
      • setHasFormatting

        public void setHasFormatting​(boolean hasFormatting)
      • 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
      • 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,
                                 java.util.Set<java.lang.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toJSON

        public java.lang.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​(java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> deltasMap)
      • applyDelta

        public void applyDelta​(java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> deltasMap,
                               boolean sanitize)
      • toDeltaMap

        public java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> toDeltaMap()
      • toDeltaMap

        public java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> toDeltaMap​(Snapshot snapshot,
                                                                                                 Snapshot prevSnapshot,
                                                                                                 java.util.function.BiFunction<java.lang.String,​ID,​java.lang.Object> computeYChange)
      • toDeltaList

        public java.util.List<Delta> toDeltaList()
      • toDeltaList

        public java.util.List<Delta> toDeltaList​(Snapshot snapshot,
                                                 Snapshot prevSnapshot,
                                                 java.util.function.BiFunction<java.lang.String,​ID,​java.lang.Object> computeYChange)
      • insert

        public void insert​(int index,
                           java.lang.String text)
      • insert

        public void insert​(int index,
                           java.lang.String text,
                           java.util.Map<java.lang.String,​java.lang.Object> attributes)
      • insertEmbed

        public void insertEmbed​(int index,
                                java.lang.Object embed)
      • insertEmbed

        public void insertEmbed​(int index,
                                java.lang.Object embed,
                                java.util.Map<java.lang.String,​java.lang.Object> attributes)
      • delete

        public void delete​(int index)
      • delete

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

        public void format​(int index,
                           int length,
                           java.util.Map<java.lang.String,​java.lang.Object> attributes)
      • removeAttribute

        public void removeAttribute​(java.lang.String attributeName)
      • setAttribute

        public void setAttribute​(java.lang.String attributeName,
                                 java.lang.Object attributeValue)
      • getAttribute

        public java.lang.Object getAttribute​(java.lang.String attributeName)
      • getAttributes

        public java.util.Map<java.lang.String,​java.lang.Object> getAttributes()
      • equalAttrs

        public static boolean equalAttrs​(java.lang.Object a,
                                         java.lang.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,
                                                   java.util.Map<java.lang.String,​java.lang.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.