pub struct XmlText(_);
Expand description
A shared data type used for collaborative text editing, that can be used in a context of XmlElement nodee. It enables multiple users to add and remove chunks of text in efficient manner. This type is internally represented as a mutable double-linked list of text chunks
- an optimization occurs during Transaction::commit, which allows to squash multiple consecutively inserted characters together as a single chunk of text even between transaction boundaries in order to preserve more efficient memory model.
Just like XmlElement, XmlText can be marked with extra metadata in form of attributes.
XmlText structure internally uses UTF-8 encoding and its length is described in a number of bytes rather than individual characters (a single UTF-8 code point can consist of many bytes).
Like all Yrs shared data types, XmlText is resistant to the problem of interleaving (situation when characters inserted one after another may interleave with other peers concurrent inserts after merging all updates together). In case of Yrs conflict resolution is solved by using unique document id to determine correct and consistent ordering.
Implementations
Returns a string representation of a current XML text.
pub fn insert_attribute<K: Into<Rc<str>>, V: AsRef<str>>(
&self,
txn: &mut Transaction,
attr_name: K,
attr_value: V
)
pub fn attributes<'a, 'b>(&'a self, txn: &'b Transaction) -> Attributes<'b>ⓘNotable traits for Attributes<'a>impl<'a> Iterator for Attributes<'a> type Item = (&'a str, String);
impl<'a> Iterator for Attributes<'a> type Item = (&'a str, String);
Returns next XML sibling of this XML text, which can be either a XmlElement, XmlText or
None
if current text is a last child of its parent XML element.
Returns previous XML sibling of this XML text, which can be either a XmlElement, XmlText
or None
if current text is a first child of its parent XML element.
Returns a parent XML element containing this XML text value.
Returns a number of characters contained under this XML text structure.
Inserts a chunk
of text at a given index
.
If index
is 0
, this chunk
will be inserted at the beginning of a current text.
If index
is equal to current data structure length, this chunk
will be appended at
the end of it.
This method will panic if provided index
is greater than the length of a current text.
pub fn insert_with_attributes(
&self,
txn: &mut Transaction,
index: u32,
content: &str,
attrs: Attrs
)
pub fn insert_with_attributes(
&self,
txn: &mut Transaction,
index: u32,
content: &str,
attrs: Attrs
)
Inserts a chunk
of text at a given index
.
If index
is 0
, this chunk
will be inserted at the beginning of a current text.
If index
is equal to current data structure length, this chunk
will be appended at
the end of it.
Collection of supplied attributes
will be used to wrap provided text chunk
range with a
formatting blocks.
This method will panic if provided index
is greater than the length of a current text.
Wraps an existing piece of text within a range described by index
-len
parameters with
formatting blocks containing provided attributes
metadata.
Inserts an embed content
at a given index
.
If index
is 0
, this content
will be inserted at the beginning of a current text.
If index
is equal to current data structure length, this embed
will be appended at
the end of it.
This method will panic if provided index
is greater than the length of a current text.
pub fn insert_embed_with_attributes(
&self,
txn: &mut Transaction,
index: u32,
content: Any,
attributes: Attrs
)
pub fn insert_embed_with_attributes(
&self,
txn: &mut Transaction,
index: u32,
content: Any,
attributes: Attrs
)
Inserts an embed content
of text at a given index
.
If index
is 0
, this content
will be inserted at the beginning of a current text.
If index
is equal to current data structure length, this chunk
will be appended at
the end of it.
Collection of supplied attributes
will be used to wrap provided text content
range with
a formatting blocks.
This method will panic if provided index
is greater than the length of a current text.
Appends a new string content
at the end of this XML text structure.
Removes a number of characters specified by a len
parameter from this XML text structure,
starting at given index
.
This method may panic if index
if greater than a length of this text.
pub fn observe<F>(&self, f: F) -> Subscription<XmlTextEvent> where
F: Fn(&Transaction, &XmlTextEvent) + 'static,
pub fn observe<F>(&self, f: F) -> Subscription<XmlTextEvent> where
F: Fn(&Transaction, &XmlTextEvent) + 'static,
Subscribes a given callback to be triggered whenever current XML text is changed. A callback is triggered whenever a transaction gets committed. This function does not trigger if changes have been observed by nested shared collections.
XML text changes can be tracked by using [Event::delta] method: keep in mind that delta contains collection of individual characters rather than strings. XML text attribute changes can be tracked using [Event::keys] method.
Returns an [Observer] which, when dropped, will unsubscribe current callback.
Unsubscribes a previously subscribed event callback identified by given subscription_id
.
Trait Implementations
Performs the conversion.
Auto Trait Implementations
impl !RefUnwindSafe for XmlText
impl !UnwindSafe for XmlText
Blanket Implementations
Mutably borrows from an owned value. Read more