Skip to main content

BatchDocument

Struct BatchDocument 

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

A headless document: no thread, no view, no cursor. See the module docs.

Implementations§

Source§

impl BatchDocument

Source

pub fn new() -> Result<Self>

Bootstrap an empty document. No I/O, no thread.

AppContext::new() gives the machinery (store, event hub, undo manager) but no entities — so, like TextDocument, this seeds the Root → Document the importer needs to hang its frames from. It stops there: TextDocument also seeds a Frame and a Block for an empty editor to show a caret in, but an import rebuilds the document’s frames anyway, and a batch has no caret to place.

stack_id: None — a batch has no undo of its own. Its caller’s transaction is the unit that gets rolled back.

Source

pub fn set_djot(&self, djot: &str, options: &DjotImportOptions) -> Result<()>

Replace the document’s contents by parsing djot.

Goes through the synchronous import path. The public import_djot hands the use case to a LongOperationManager, which spawns a thread for it — the very thing this type exists to avoid.

Source

pub fn to_djot(&self, options: &DjotExportOptions) -> Result<String>

Serialise the document back to Djot.

Source

pub fn find_all( &self, query: &str, options: &FindOptions, ) -> Result<Vec<FindMatch>>

Every match of query in the document’s text.

Positions are char indices into the document’s own text — the same space every other offset in this crate lives in. They are emphatically not byte offsets into the Djot source the document was parsed from: markup means the two disagree on almost any real paragraph, and mixing them corrupts a replace.

Source

pub fn find_and_replace( &self, query: &str, options: &ReplaceOptions, decide: impl FnMut(&str, usize) -> Option<String>, ) -> Result<usize>

Find every match of query and let decide choose what each becomes — the whole thing in one shot.

decide is handed the matched text and the index of the match, and returns the replacement, or None to leave that occurrence alone. That is exactly what a reviewed bulk rename needs: skip the occurrences the writer unticked, and preserve the case of the ones that stay (AURÉLIENAURÉLIAN, not aurélian).

This is why a backend batch can stop doing string surgery on markup. The alternative — export the Djot and rewrite it as a string — rewrites a query that also occurs inside a link’s URL, and drops the character formatting under every match. Here the edit happens inside the document, at the offsets the parser itself reports, and ReplaceOptions::format_policy decides what the replacement wears where it overwrites formatted prose.

The matched text comes back from the scan itself, sliced from the very text that was searched — never from a plain-text export, which is the human-readable view and does not carry the U+FFFC anchor an embedded table occupies.

Source

pub fn replace_ranges( &self, ranges: &[ReplaceRange], options: &ReplaceOptions, ) -> Result<usize>

Replace an explicit set of ranges, each with its own replacement text.

Ranges that straddle a block boundary, or that overlap one another, are skipped; the returned count is what was actually applied. Prefer Self::find_and_replace, which derives the ranges from a scan of the document as it stands, so they cannot address text that has since moved.

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.