Make block ids mandatory

This commit is contained in:
Joscha 2022-06-13 23:16:30 +02:00
parent fc7b01b8c2
commit 6e9216913e

View file

@ -17,7 +17,7 @@ const INDENT_WIDTH: usize = 2;
struct Block<I> { struct Block<I> {
line: i32, line: i32,
height: i32, height: i32,
id: Option<I>, id: I,
indent: usize, indent: usize,
cursor: bool, cursor: bool,
content: BlockContent, content: BlockContent,
@ -28,7 +28,7 @@ impl<I> Block<I> {
Self { Self {
line: 0, line: 0,
height: 1, height: 1,
id: Some(id), id,
indent, indent,
cursor: false, cursor: false,
content: BlockContent::Placeholder, content: BlockContent::Placeholder,
@ -52,7 +52,7 @@ impl MsgBlock {
Block { Block {
line: 0, line: 0,
height: self.lines.len() as i32, height: self.lines.len() as i32,
id: Some(id), id,
indent, indent,
cursor: false, cursor: false,
content: BlockContent::Msg(self), content: BlockContent::Msg(self),
@ -105,7 +105,7 @@ impl<I: PartialEq> Layout<I> {
fn mark_cursor(&mut self, id: &I) -> usize { fn mark_cursor(&mut self, id: &I) -> usize {
let mut cursor = None; let mut cursor = None;
for (i, block) in self.blocks.iter_mut().enumerate() { for (i, block) in self.blocks.iter_mut().enumerate() {
if block.id.as_ref() == Some(id) { if &block.id == id {
block.cursor = true; block.cursor = true;
if cursor.is_some() { if cursor.is_some() {
panic!("more than one cursor in layout"); panic!("more than one cursor in layout");