Fetch older messages when scrolling up in the chat message list

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld
2021-08-27 14:58:28 -07:00
co-authored by Nathan Sobo
parent 5262dcd3cb
commit bc63fca8d7
8 changed files with 281 additions and 68 deletions
+14
View File
@@ -29,6 +29,7 @@ struct StateInner {
heights: SumTree<ElementHeight>,
scroll_position: f32,
orientation: Orientation,
scroll_handler: Option<Box<dyn FnMut(Range<usize>, &mut EventContext)>>,
}
#[derive(Clone, Debug)]
@@ -272,6 +273,7 @@ impl ListState {
heights,
scroll_position: 0.,
orientation,
scroll_handler: None,
})))
}
@@ -290,6 +292,13 @@ impl ListState {
drop(old_heights);
state.heights = new_heights;
}
pub fn set_scroll_handler(
&mut self,
handler: impl FnMut(Range<usize>, &mut EventContext) + 'static,
) {
self.0.borrow_mut().scroll_handler = Some(Box::new(handler))
}
}
impl StateInner {
@@ -320,6 +329,11 @@ impl StateInner {
Orientation::Bottom => delta.y(),
};
self.scroll_position = (self.scroll_position + delta_y).max(0.).min(scroll_max);
if self.scroll_handler.is_some() {
let range = self.visible_range(height);
self.scroll_handler.as_mut().unwrap()(range, cx);
}
cx.notify();
true