Move to prev/next unseen message

This commit is contained in:
Joscha 2022-08-08 16:59:24 +02:00
parent 05ce069121
commit bfc221106d
5 changed files with 225 additions and 0 deletions

View file

@ -65,6 +65,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
pub fn list_movement_key_bindings(&self, bindings: &mut KeyBindingsList) {
bindings.binding("j/k, ↓/↑", "move cursor up/down");
bindings.binding("h/l, ←/→", "move cursor chronologically");
bindings.binding("H/L, ctrl+←/→", "move cursor to prev/next unseen message");
bindings.binding("g, home", "move cursor to top");
bindings.binding("G, end", "move cursor to bottom");
bindings.binding("ctrl+y/e", "scroll up/down a line");
@ -80,6 +81,8 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
key!('j') | key!(Down) => self.move_cursor_down().await,
key!('h') | key!(Left) => self.move_cursor_older().await,
key!('l') | key!(Right) => self.move_cursor_newer().await,
key!('H') | key!(Ctrl + Left) => self.move_cursor_older_unseen().await,
key!('L') | key!(Ctrl + Right) => self.move_cursor_newer_unseen().await,
key!('g') | key!(Home) => self.move_cursor_to_top().await,
key!('G') | key!(End) => self.move_cursor_to_bottom().await,
key!(Ctrl + 'y') => self.scroll_up(1),

View file

@ -254,6 +254,40 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
self.correction = Some(Correction::MakeCursorVisible);
}
pub async fn move_cursor_older_unseen(&mut self) {
match &mut self.cursor {
Cursor::Msg(id) => {
if let Some(prev_id) = self.store.older_unseen_msg_id(id).await {
*id = prev_id;
}
}
Cursor::Bottom | Cursor::Pseudo { .. } => {
if let Some(id) = self.store.newest_unseen_msg_id().await {
self.cursor = Cursor::Msg(id);
}
}
_ => {}
}
self.correction = Some(Correction::MakeCursorVisible);
}
pub async fn move_cursor_newer_unseen(&mut self) {
match &mut self.cursor {
Cursor::Msg(id) => {
if let Some(prev_id) = self.store.newer_unseen_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);