Skip to main content

Transform

Struct Transform 

Source
pub struct Transform { /* private fields */ }
Expand description

An accumulating, invertible batch of document changes.

Implementations§

Source§

impl Transform

Source

pub fn new(doc: Node) -> Self

Start a transform from doc.

Source

pub fn doc(&self) -> &Node

The current document (after the steps applied so far).

Source

pub fn steps(&self) -> &[Box<dyn Step>]

The steps applied so far.

Source

pub fn doc_before(&self, i: usize) -> &Node

The document before step i.

Source

pub fn mapping(&self) -> &Mapping

The combined position mapping for all steps so far.

Source

pub fn doc_changed(&self) -> bool

Whether any step has been applied.

Source

pub fn step( &mut self, step: Box<dyn Step>, schema: &Schema, ) -> Result<&mut Self, StepError>

Apply step, recording the prior document and its map.

Source

pub fn replace( &mut self, from: usize, to: usize, slice: Slice, schema: &Schema, ) -> Result<&mut Self, StepError>

Replace from..to with slice.

Source

pub fn delete( &mut self, from: usize, to: usize, schema: &Schema, ) -> Result<&mut Self, StepError>

Delete from..to.

Source

pub fn insert( &mut self, pos: usize, slice: Slice, schema: &Schema, ) -> Result<&mut Self, StepError>

Insert slice at pos.

Source

pub fn add_mark( &mut self, from: usize, to: usize, mark: Mark, schema: &Schema, ) -> Result<&mut Self, StepError>

Add mark across from..to.

Source

pub fn remove_mark( &mut self, from: usize, to: usize, mark: Mark, schema: &Schema, ) -> Result<&mut Self, StepError>

Remove mark across from..to.

Source

pub fn split( &mut self, pos: usize, schema: &Schema, ) -> Result<&mut Self, StepError>

Split the textblock at pos into two blocks of the same type (depth-1 split — the common Enter behaviour).

Source

pub fn split_at_depth( &mut self, pos: usize, levels: usize, schema: &Schema, ) -> Result<&mut Self, StepError>

Split at pos all the way up to levels ancestors (so levels = 1 is the regular textblock split, levels = 2 splits a list_item + its paragraph, etc.). The split inserts levels pairs of (close, open) at pos; everything before stays in the first copy of each wrapper, everything after moves into the second.

Source

pub fn set_node_attr( &mut self, pos: usize, attr: &str, value: Value, schema: &Schema, ) -> Result<&mut Self, StepError>

Set attribute attr to value on the node at pos.

Source

pub fn invert_steps(&self) -> Result<Vec<Box<dyn Step>>, StepError>

Invert every step (last-first) against the document it applied to, yielding the steps that undo this whole transform.

Trait Implementations§

Source§

impl Clone for Transform

Source§

fn clone(&self) -> Transform

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Transform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.