Skip to main content

logical_offset_to_byte

Function logical_offset_to_byte 

Source
pub fn logical_offset_to_byte(
    plain_text: &str,
    images: &[ImageAnchor],
    char_offset: i64,
) -> u32
Expand description

Translate a logical character offset (counting text characters AND image positions interleaved by their byte_offset) into a UTF-8 byte offset within plain_text. Used by writer use cases to map a document-space char position to the byte position where text edits should land in block.plain_text.

Images contribute 1 logical character but 0 bytes in plain_text. Images at the same byte_offset are visited in their stored order.