Move cursor chronologically

This commit is contained in:
Joscha 2022-08-03 01:58:49 +02:00
parent 1f19b4cdf5
commit 042f0ab78d
2 changed files with 36 additions and 0 deletions

View file

@ -139,6 +139,8 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
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),

View file

@ -211,6 +211,40 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
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);