diff --git a/src/ui/chat/tree.rs b/src/ui/chat/tree.rs index 6b694e8..c24b787 100644 --- a/src/ui/chat/tree.rs +++ b/src/ui/chat/tree.rs @@ -139,6 +139,8 @@ impl> InnerTreeViewState { match event.code { KeyCode::Char('k') | KeyCode::Up if shift_only => self.move_cursor_up().await, KeyCode::Char('j') | KeyCode::Down if shift_only => self.move_cursor_down().await, + KeyCode::Char('h') | KeyCode::Left if shift_only => self.move_cursor_older().await, + KeyCode::Char('l') | KeyCode::Right if shift_only => self.move_cursor_newer().await, KeyCode::Char('g') | KeyCode::Home if shift_only => self.move_cursor_to_top().await, KeyCode::Char('G') | KeyCode::End if shift_only => self.move_cursor_to_bottom().await, KeyCode::Char('y') if event.modifiers == KeyModifiers::CONTROL => self.scroll_up(1), diff --git a/src/ui/chat/tree/cursor.rs b/src/ui/chat/tree/cursor.rs index 1a1003c..79a0caf 100644 --- a/src/ui/chat/tree/cursor.rs +++ b/src/ui/chat/tree/cursor.rs @@ -211,6 +211,40 @@ impl> InnerTreeViewState { self.correction = Some(Correction::MakeCursorVisible); } + pub async fn move_cursor_older(&mut self) { + match &mut self.cursor { + Cursor::Msg(id) => { + if let Some(prev_id) = self.store.older_msg_id(id).await { + *id = prev_id; + } + } + Cursor::Bottom | Cursor::Pseudo { .. } => { + if let Some(id) = self.store.newest_msg_id().await { + self.cursor = Cursor::Msg(id); + } + } + _ => {} + } + self.correction = Some(Correction::MakeCursorVisible); + } + + pub async fn move_cursor_newer(&mut self) { + match &mut self.cursor { + Cursor::Msg(id) => { + if let Some(prev_id) = self.store.newer_msg_id(id).await { + *id = prev_id; + } else { + self.cursor = Cursor::Bottom; + } + } + Cursor::Pseudo { .. } => { + self.cursor = Cursor::Bottom; + } + _ => {} + } + self.correction = Some(Correction::MakeCursorVisible); + } + pub async fn move_cursor_to_top(&mut self) { if let Some(first_tree_id) = self.store.first_tree_id().await { self.cursor = Cursor::Msg(first_tree_id);