Skip to main content

TextBlock

Struct TextBlock 

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

A lightweight, read-only handle to a single block (paragraph).

Holds a stable entity ID — the handle remains valid across edits that insert or remove other blocks. Each method acquires the document lock independently. For consistent reads across multiple fields, use snapshot().

Implementations§

Source§

impl TextBlock

Source

pub fn text(&self) -> String

Block’s plain text. O(1).

Source

pub fn length(&self) -> usize

Character count. O(1).

Source

pub fn is_empty(&self) -> bool

length() == 0. O(1).

Source

pub fn is_valid(&self) -> bool

Block entity still exists in the database. O(1).

Source

pub fn id(&self) -> usize

Stable entity ID (stored in the handle). O(1).

Source

pub fn position(&self) -> usize

Character offset from Block.document_position. O(1).

Source

pub fn block_number(&self) -> usize

Global 0-indexed block number. O(n): requires scanning all blocks sorted by document_position. Prefer id() for identity and position() for ordering.

Source

pub fn next(&self) -> Option<TextBlock>

The next block in document order. O(n). Returns None if this is the last block.

Source

pub fn previous(&self) -> Option<TextBlock>

The previous block in document order. O(n). Returns None if this is the first block.

Source

pub fn frame(&self) -> TextFrame

Parent frame. O(1).

Source

pub fn table_cell(&self) -> Option<TableCellRef>

If inside a table cell, returns table and cell coordinates.

Finds the block’s parent frame, then checks if any table cell references that frame as its cell_frame. If so, identifies the owning table.

Source

pub fn block_format(&self) -> BlockFormat

Block format (alignment, margins, indent, heading level, marker, tabs). O(1).

Source

pub fn char_format_at(&self, offset: usize) -> Option<TextFormat>

Character format at a block-relative character offset. O(k) where k = number of InlineElements.

Returns the TextFormat of the fragment containing the given offset. Returns None if the offset is out of range or the block has no fragments.

Source

pub fn fragments(&self) -> Vec<FragmentContent>

All formatting runs in one call. O(k) where k = number of InlineElements.

Source

pub fn list(&self) -> Option<TextList>

List this block belongs to. O(1).

Source

pub fn list_item_index(&self) -> Option<usize>

0-based position within its list. O(n) where n = total blocks.

Source

pub fn snapshot(&self) -> BlockSnapshot

All layout-relevant data in one lock acquisition. O(k+n).

Trait Implementations§

Source§

impl Clone for TextBlock

Source§

fn clone(&self) -> TextBlock

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. 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.