Scroll with ctrl+e and ctrl+d

This commit is contained in:
Joscha 2022-07-31 23:09:39 +02:00
parent d23d7b155c
commit cb2fc22c5a
3 changed files with 28 additions and 5 deletions

View file

@ -223,6 +223,23 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
// Not really necessary; only here for consistency with other methods
self.make_cursor_visible = true;
}
pub async fn scroll_up(&mut self, amount: i32) {
self.scroll += amount;
if let Cursor::Bottom = self.cursor {
// Move cursor to bottommost message, if it exists
if let Some(mut id) = self.store.last_tree_id().await {
let tree = self.store.tree(&id).await;
while Self::find_last_child(&tree, &mut id) {}
self.cursor = Cursor::Msg(id);
}
}
}
pub fn scroll_down(&mut self, amount: i32) {
self.scroll -= amount;
}
}
/*

View file

@ -285,7 +285,8 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
// The basic idea is this:
//
// First, layout a full screen of blocks around self.last_cursor, using
// self.last_cursor_line for offset positioning.
// self.last_cursor_line for offset positioning. At this point, any
// outstanding scrolling is performed as well.
//
// Then, check if self.cursor is somewhere in these blocks. If it is, we
// now know the position of our own cursor. If it is not, it has jumped
@ -305,6 +306,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
let mut blocks = self
.layout_initial_seed(frame, &last_cursor_path, &cursor_path)
.await;
blocks.blocks_mut().offset(self.scroll);
self.fill_screen_and_clamp_scrolling(frame, &mut blocks)
.await;
@ -329,6 +331,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
self.last_cursor = self.cursor.clone();
self.last_cursor_line = self.cursor_line(&blocks);
self.make_cursor_visible = false;
self.scroll = 0;
blocks
}