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
impl TextBlock
Sourcepub fn position(&self) -> usize
pub fn position(&self) -> usize
Character offset of this block’s start in the document. O(log n) via the rope index for rope-clean documents; O(1) read of the stored field for tabled documents.
Sourcepub fn block_number(&self) -> usize
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.
Sourcepub fn next(&self) -> Option<TextBlock>
pub fn next(&self) -> Option<TextBlock>
The next block in document order. O(n).
Returns None if this is the last block.
Sourcepub fn previous(&self) -> Option<TextBlock>
pub fn previous(&self) -> Option<TextBlock>
The previous block in document order. O(n).
Returns None if this is the first block.
Sourcepub fn table_cell(&self) -> Option<TableCellRef>
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.
Sourcepub fn block_format(&self) -> BlockFormat
pub fn block_format(&self) -> BlockFormat
Block format (alignment, margins, indent, heading level, marker, tabs). O(1).
Sourcepub fn char_format_at(&self, offset: usize) -> Option<TextFormat>
pub fn char_format_at(&self, offset: usize) -> Option<TextFormat>
Character format at a block-relative character offset. O(k) where k = format runs + image anchors in this block.
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.
Sourcepub fn fragments(&self) -> Vec<FragmentContent>
pub fn fragments(&self) -> Vec<FragmentContent>
Shaping-input fragments: base formatting plus any metric-affecting
syntax highlights (bold / italic / size / family / spacing). This is
what the layout engine shapes. Paint-only highlights (colors,
underline decorations) are NOT merged here — they are kept separate
in BlockSnapshot::paint_highlights
as a post-shape recolor overlay, so the shaping input stays stable
across paint-only highlight changes. For the fully-merged visual
fragments, use display_fragments.
O(k) where k = format runs + image anchors in this block.
Sourcepub fn display_fragments(&self) -> Vec<FragmentContent>
pub fn display_fragments(&self) -> Vec<FragmentContent>
Fragments as they should be displayed: base formatting with all
active syntax highlights merged in, including paint-only ones. This is
the “what it looks like” view — useful for a non-optimized renderer,
for accessibility, or for tests. The optimized layout path instead uses
fragments (shaping input) plus the separate
BlockSnapshot::paint_highlights
overlay. Equivalent to the pre-overlay behaviour of fragments().
Sourcepub fn list_item_index(&self) -> Option<usize>
pub fn list_item_index(&self) -> Option<usize>
0-based position within its list. O(n) where n = total blocks.
Sourcepub fn snapshot(&self) -> BlockSnapshot
pub fn snapshot(&self) -> BlockSnapshot
All layout-relevant data in one lock acquisition. O(k+n).