use crate::database::Store;
use crate::database::rope_helpers::block_document_position;
use crate::entities::Block;
use crate::format_runs::{
AddressableInlinePiece, FootnoteRefAnchor, FormatRun, ImageAnchor, InlineSegment,
addressable_inline_pieces, block_anchors, inline_segments_view,
};
use crate::types::EntityId;
pub fn get_format_runs(store: &Store, block_id: EntityId) -> Vec<FormatRun> {
store
.format_runs
.read()
.get(&block_id)
.cloned()
.unwrap_or_default()
}
pub fn get_block_footnote_refs(store: &Store, block_id: EntityId) -> Vec<FootnoteRefAnchor> {
store
.block_footnote_refs
.read()
.get(&block_id)
.cloned()
.unwrap_or_default()
}
pub fn get_block_images(store: &Store, block_id: EntityId) -> Vec<ImageAnchor> {
store
.block_images
.read()
.get(&block_id)
.cloned()
.unwrap_or_default()
}
pub fn inline_segments_for_block(
store: &Store,
block_id: EntityId,
block_plain_text: &str,
) -> Vec<InlineSegment> {
let runs = get_format_runs(store, block_id);
let images = get_block_images(store, block_id);
let notes = get_block_footnote_refs(store, block_id);
inline_segments_view(block_plain_text, &runs, &images, ¬es)
}
pub fn addressable_inline_pieces_for_block(
store: &Store,
block: &Block,
block_plain_text: &str,
) -> Vec<AddressableInlinePiece> {
let runs = get_format_runs(store, block.id);
let images = get_block_images(store, block.id);
let notes = get_block_footnote_refs(store, block.id);
let anchors = block_anchors(&images, ¬es);
let base_char_offset = block_document_position(block, store) as u32;
addressable_inline_pieces(block_plain_text, &runs, &anchors, base_char_offset)
}