use crate::ui::chat::blocks::Blocks; use super::Cursor; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum BlockId { Msg(I), Cursor, LastCursor, } impl BlockId { pub fn from_cursor(cursor: &Cursor) -> Self { match cursor { Cursor::Msg(id) => Self::Msg(id.clone()), _ => Self::Cursor, } } } #[derive(Debug, Clone, Copy)] pub enum Root { Bottom, Tree(I), } pub struct TreeBlocks { blocks: Blocks>, top_root: Root, bottom_root: Root, } impl TreeBlocks { pub fn new(top_root: Root, bottom_root: Root) -> Self { Self { blocks: Blocks::new(), top_root, bottom_root, } } pub fn blocks(&self) -> &Blocks> { &self.blocks } pub fn blocks_mut(&mut self) -> &mut Blocks> { &mut self.blocks } pub fn into_blocks(self) -> Blocks> { self.blocks } pub fn top_root(&self) -> &Root { &self.top_root } pub fn bottom_root(&self) -> &Root { &self.bottom_root } pub fn prepend(&mut self, other: Self) { self.blocks.prepend(other.blocks); self.top_root = other.top_root; } pub fn append(&mut self, other: Self) { self.blocks.append(other.blocks); self.bottom_root = other.bottom_root; } }