pub struct YXmlText(_);Expand description
A shared data type used for collaborative text editing, that can be used in a context of
YXmlElement 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
YTransaction.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 YXmlElement, YXmlText can be marked with extra metadata in form of attributes.
YXmlText 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, YXmlText 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
sourceimpl YXmlText
impl YXmlText
sourcepub fn length(&self) -> u32
pub fn length(&self) -> u32
Returns length of an underlying string stored in this YXmlText instance,
understood as a number of UTF-8 encoded bytes.
sourcepub fn insert(
&self,
txn: &mut YTransaction,
index: i32,
chunk: &str,
attrs: JsValue
)
pub fn insert(
&self,
txn: &mut YTransaction,
index: i32,
chunk: &str,
attrs: JsValue
)
Inserts a given chunk of text into this YXmlText instance, starting at a given index.
Optional object with defined attributes will be used to wrap provided text chunk
with a formatting blocks.
sourcepub fn format(
&self,
txn: &mut YTransaction,
index: i32,
len: i32,
attrs: JsValue
)
pub fn format(
&self,
txn: &mut YTransaction,
index: i32,
len: i32,
attrs: JsValue
)
Formats text within bounds specified by index and len with a given formatting
attributes.
sourcepub fn insert_embed(
&self,
txn: &mut YTransaction,
index: u32,
embed: JsValue,
attributes: JsValue
)
pub fn insert_embed(
&self,
txn: &mut YTransaction,
index: u32,
embed: JsValue,
attributes: JsValue
)
Inserts a given embed object into this YXmlText instance, starting at a given index.
Optional object with defined attributes will be used to wrap provided embed
with a formatting blocks.attributes are only supported for a YXmlText instance which
already has been integrated into document store.
sourcepub fn push(&self, txn: &mut YTransaction, chunk: &str, attrs: JsValue)
pub fn push(&self, txn: &mut YTransaction, chunk: &str, attrs: JsValue)
Appends a given chunk of text at the end of YXmlText instance.
Optional object with defined attributes will be used to wrap provided text chunk
with a formatting blocks.
sourcepub fn delete(&self, txn: &mut YTransaction, index: u32, length: u32)
pub fn delete(&self, txn: &mut YTransaction, index: u32, length: u32)
Deletes a specified range of of characters, starting at a given index.
Both index and length are counted in terms of a number of UTF-8 character bytes.
sourcepub fn next_sibling(&self) -> JsValue
pub fn next_sibling(&self) -> JsValue
Returns a next XML sibling node of this XMl node.
It can be either YXmlElement, YXmlText or undefined if current node is a last child of
parent XML node.
sourcepub fn prev_sibling(&self) -> JsValue
pub fn prev_sibling(&self) -> JsValue
Returns a previous XML sibling node of this XMl node.
It can be either YXmlElement, YXmlText or undefined if current node is a first child
of parent XML node.
sourcepub fn parent(&self) -> JsValue
pub fn parent(&self) -> JsValue
Returns a parent YXmlElement node or undefined if current node has no parent assigned.
sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Returns an underlying string stored in this YXmlText instance.
sourcepub fn set_attribute(&self, txn: &mut YTransaction, name: &str, value: &str)
pub fn set_attribute(&self, txn: &mut YTransaction, name: &str, value: &str)
Sets a name and value as new attribute for this XML node. If an attribute with the same
name already existed on that node, its value with be overridden with a provided one.
sourcepub fn get_attribute(&self, name: &str) -> Option<String>
pub fn get_attribute(&self, name: &str) -> Option<String>
Returns a value of an attribute given its name. If no attribute with such name existed,
null will be returned.
sourcepub fn remove_attribute(&self, txn: &mut YTransaction, name: &str)
pub fn remove_attribute(&self, txn: &mut YTransaction, name: &str)
Removes an attribute from this XML node, given its name.
sourcepub fn attributes(&self) -> YXmlAttributes
pub fn attributes(&self) -> YXmlAttributes
Returns an iterator that enables to traverse over all attributes of this XML node in unspecified order.
sourcepub fn observe(&mut self, f: Function) -> YXmlTextObserver
pub fn observe(&mut self, f: Function) -> YXmlTextObserver
Subscribes to all operations happening over this instance of YXmlText. All changes are
batched and eventually triggered during transaction commit phase.
Returns an YObserver which, when free’d, will unsubscribe current callback.
sourcepub fn observe_deep(&mut self, f: Function) -> YEventObserver
pub fn observe_deep(&mut self, f: Function) -> YEventObserver
Subscribes to all operations happening over this Y shared type, as well as events in
shared types stored within this one. All changes are batched and eventually triggered
during transaction commit phase.
Returns an YEventObserver which, when free’d, will unsubscribe current callback.
Trait Implementations
sourceimpl FromWasmAbi for YXmlText
impl FromWasmAbi for YXmlText
sourceimpl IntoWasmAbi for YXmlText
impl IntoWasmAbi for YXmlText
sourceimpl OptionFromWasmAbi for YXmlText
impl OptionFromWasmAbi for YXmlText
sourceimpl OptionIntoWasmAbi for YXmlText
impl OptionIntoWasmAbi for YXmlText
sourceimpl RefFromWasmAbi for YXmlText
impl RefFromWasmAbi for YXmlText
type Anchor = Ref<'static, YXmlText>
type Anchor = Ref<'static, YXmlText>
The type that holds the reference to Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous. Read more
sourceunsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
Recover a Self::Anchor from Self::Abi. Read more
sourceimpl RefMutFromWasmAbi for YXmlText
impl RefMutFromWasmAbi for YXmlText
Auto Trait Implementations
impl !RefUnwindSafe for YXmlText
impl !Send for YXmlText
impl !Sync for YXmlText
impl Unpin for YXmlText
impl !UnwindSafe for YXmlText
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ReturnWasmAbi for T where
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for T where
T: IntoWasmAbi,
type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
Same as IntoWasmAbi::Abi
sourcefn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
Same as IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err. Read more