Fetch older messages when scrolling up in the chat message list
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
co-authored by
Nathan Sobo
parent
5262dcd3cb
commit
bc63fca8d7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user