diff --git a/CHANGELOG.md b/CHANGELOG.md index 870f0ce..6f9a098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Procedure when bumping the version number: - `euph.rooms..password` config option - Key binding to change rooms sort order - Key bindings to connect to/disconnect from all rooms +- Key bindings to move to parent/root message ### Changed - Some key bindings in the rooms list diff --git a/src/ui/chat/tree.rs b/src/ui/chat/tree.rs index 4087094..e054855 100644 --- a/src/ui/chat/tree.rs +++ b/src/ui/chat/tree.rs @@ -69,6 +69,7 @@ impl> InnerTreeViewState { pub fn list_movement_key_bindings(&self, bindings: &mut KeyBindingsList) { bindings.binding("j/k, ↓/↑", "move cursor up/down"); 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, ctrl+←/→", "move cursor to prev/next unseen message"); bindings.binding("g, home", "move cursor to top"); @@ -87,6 +88,8 @@ impl> InnerTreeViewState { key!('j') | key!(Down) => self.move_cursor_down().await, key!('K') | key!(Ctrl + Up) => self.move_cursor_up_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!('l') | key!(Right) => self.move_cursor_newer().await, key!('H') | key!(Ctrl + Left) => self.move_cursor_older_unseen().await, diff --git a/src/ui/chat/tree/cursor.rs b/src/ui/chat/tree/cursor.rs index de24c43..94f5487 100644 --- a/src/ui/chat/tree/cursor.rs +++ b/src/ui/chat/tree/cursor.rs @@ -288,6 +288,41 @@ impl> InnerTreeViewState { 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) { match &mut self.cursor { Cursor::Msg(id) => {