From 4cf0d861db328765786e6f083c0aacb3b520f7a8 Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 20 Jul 2022 08:43:00 +0200 Subject: [PATCH] Clean up --- src/ui/chat/tree/layout.rs | 74 +++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/ui/chat/tree/layout.rs b/src/ui/chat/tree/layout.rs index 473c008..e1582db 100644 --- a/src/ui/chat/tree/layout.rs +++ b/src/ui/chat/tree/layout.rs @@ -4,7 +4,7 @@ use toss::frame::{Frame, Size}; use crate::store::{Msg, MsgStore, Path, Tree}; -use super::blocks::{Block, BlockBody, Blocks, MarkerBlock, MsgBlock}; +use super::blocks::{Block, BlockBody, Blocks, MsgBlock}; use super::{util, Cursor, InnerTreeViewState}; impl> InnerTreeViewState { @@ -144,18 +144,18 @@ impl> InnerTreeViewState { return; } - if let Some(block) = blocks.find(|b| cursor.matches_block(b)) { - let min_line = 0; - let max_line = size.height as i32 - block.height(); - if block.line < min_line { - blocks.offset(min_line - block.line); - } else if block.line > max_line { - blocks.offset(max_line - block.line); - } - } else { + let block = blocks + .find(|b| cursor.matches_block(b)) // This should never happen since we always start rendering the // blocks from the cursor. - panic!("no cursor found"); + .expect("no cursor found"); + + let min_line = 0; + let max_line = size.height as i32 - block.height(); + if block.line < min_line { + blocks.offset(min_line - block.line); + } else if block.line > max_line { + blocks.offset(max_line - block.line); } } @@ -178,34 +178,34 @@ impl> InnerTreeViewState { return; } - if let Some(block) = blocks.find(|b| cursor.matches_block(b)) { - let min_line = 1 - block.height(); - let max_line = size.height as i32 - 1; - - let new_cursor = if block.line < min_line { - // Move cursor to first possible visible block - blocks - .iter() - .filter(|b| b.line >= min_line) - .find_map(Self::as_msg_cursor) - } else if block.line > max_line { - // Move cursor to last possible visible block - blocks - .iter() - .rev() - .filter(|b| b.line <= max_line) - .find_map(Self::as_msg_cursor) - } else { - None - }; - - if let Some(new_cursor) = new_cursor { - *cursor = new_cursor; - } - } else { + let block = blocks + .find(|b| cursor.matches_block(b)) // This should never happen since we always start rendering the // blocks from the cursor. - panic!("no cursor found"); + .expect("no cursor found"); + + let min_line = 1 - block.height(); + let max_line = size.height as i32 - 1; + + let new_cursor = if block.line < min_line { + // Move cursor to first possible visible block + blocks + .iter() + .filter(|b| b.line >= min_line) + .find_map(Self::as_msg_cursor) + } else if block.line > max_line { + // Move cursor to last possible visible block + blocks + .iter() + .rev() + .filter(|b| b.line <= max_line) + .find_map(Self::as_msg_cursor) + } else { + None + }; + + if let Some(new_cursor) = new_cursor { + *cursor = new_cursor; } }