Add key bindings to move to parent/root message

This commit is contained in:
JRF 2022-08-26 20:47:01 -05:00 committed by Joscha
parent 827a854101
commit 7e086258b6
3 changed files with 39 additions and 0 deletions

View file

@ -25,6 +25,7 @@ Procedure when bumping the version number:
- `euph.rooms.<name>.password` config option - `euph.rooms.<name>.password` config option
- Key binding to change rooms sort order - Key binding to change rooms sort order
- Key bindings to connect to/disconnect from all rooms - Key bindings to connect to/disconnect from all rooms
- Key bindings to move to parent/root message
### Changed ### Changed
- Some key bindings in the rooms list - Some key bindings in the rooms list

View file

@ -69,6 +69,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
pub fn list_movement_key_bindings(&self, bindings: &mut KeyBindingsList) { pub fn list_movement_key_bindings(&self, bindings: &mut KeyBindingsList) {
bindings.binding("j/k, ↓/↑", "move cursor up/down"); bindings.binding("j/k, ↓/↑", "move cursor up/down");
bindings.binding("J/K, ctrl+↓/↑", "move cursor to prev/next sibling"); bindings.binding("J/K, ctrl+↓/↑", "move cursor to prev/next sibling");
bindings.binding("p/P", "move cursor to parent/root");
bindings.binding("h/l, ←/→", "move cursor chronologically"); bindings.binding("h/l, ←/→", "move cursor chronologically");
bindings.binding("H/L, ctrl+←/→", "move cursor to prev/next unseen message"); bindings.binding("H/L, ctrl+←/→", "move cursor to prev/next unseen message");
bindings.binding("g, home", "move cursor to top"); bindings.binding("g, home", "move cursor to top");
@ -87,6 +88,8 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
key!('j') | key!(Down) => self.move_cursor_down().await, key!('j') | key!(Down) => self.move_cursor_down().await,
key!('K') | key!(Ctrl + Up) => self.move_cursor_up_sibling().await, key!('K') | key!(Ctrl + Up) => self.move_cursor_up_sibling().await,
key!('J') | key!(Ctrl + Down) => self.move_cursor_down_sibling().await, key!('J') | key!(Ctrl + Down) => self.move_cursor_down_sibling().await,
key!('p') => self.move_cursor_to_parent().await,
key!('P') => self.move_cursor_to_root().await,
key!('h') | key!(Left) => self.move_cursor_older().await, key!('h') | key!(Left) => self.move_cursor_older().await,
key!('l') | key!(Right) => self.move_cursor_newer().await, key!('l') | key!(Right) => self.move_cursor_newer().await,
key!('H') | key!(Ctrl + Left) => self.move_cursor_older_unseen().await, key!('H') | key!(Ctrl + Left) => self.move_cursor_older_unseen().await,

View file

@ -288,6 +288,41 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
self.correction = Some(Correction::MakeCursorVisible); self.correction = Some(Correction::MakeCursorVisible);
} }
pub async fn move_cursor_to_parent(&mut self) {
match &mut self.cursor {
Cursor::Pseudo {
parent: Some(parent),
..
} => self.cursor = Cursor::Msg(parent.clone()),
Cursor::Msg(id) => {
// Could also be done via retrieving the path, but it doesn't
// really matter here
let tree = self.store.tree(id).await;
Self::find_parent(&tree, id);
}
_ => {}
}
self.correction = Some(Correction::MakeCursorVisible);
}
pub async fn move_cursor_to_root(&mut self) {
match &mut self.cursor {
Cursor::Pseudo {
parent: Some(parent),
..
} => {
let path = self.store.path(parent).await;
self.cursor = Cursor::Msg(path.first().clone());
}
Cursor::Msg(msg) => {
let path = self.store.path(msg).await;
*msg = path.first().clone();
}
_ => {}
}
self.correction = Some(Correction::MakeCursorVisible);
}
pub async fn move_cursor_older(&mut self) { pub async fn move_cursor_older(&mut self) {
match &mut self.cursor { match &mut self.cursor {
Cursor::Msg(id) => { Cursor::Msg(id) => {