list: Fix list item may overflow. (#1726)

Closes #1692
This commit is contained in:
Jason Lee 2025-12-02 13:33:47 +08:00 committed by GitHub
parent 64aa975c77
commit 8abaa82233
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 9 deletions

View file

@ -270,7 +270,12 @@ impl ListDelegate for CompanyListDelegate {
)
}
fn render_item(&mut self, ix: IndexPath, _: &mut Window, _: &mut Context<ListState<Self>>) -> Option<Self::Item> {
fn render_item(
&mut self,
ix: IndexPath,
_: &mut Window,
_: &mut Context<ListState<Self>>,
) -> Option<Self::Item> {
let selected = Some(ix) == self.selected_index || Some(ix) == self.confirmed_index;
if let Some(company) = self.matched_companies[ix.section].get(ix.row) {
return Some(CompanyListItem::new(ix, company.clone(), selected));

View file

@ -147,10 +147,6 @@ impl RowsCache {
path
}
pub(crate) fn measured_size(&self) -> MeasuredEntrySize {
self.measured_size
}
pub(crate) fn prepare_if_needed<F>(
&mut self,
sections_count: usize,
@ -207,7 +203,7 @@ impl RowsCache {
mod tests {
use std::rc::Rc;
use crate::{list::cache::RowsCache, IndexPath};
use crate::{IndexPath, list::cache::RowsCache};
#[test]
fn test_prev_next() {

View file

@ -66,6 +66,8 @@ impl Default for ListOptions {
}
/// The state for List.
///
/// List required all items has the same height.
pub struct ListState<D: ListDelegate> {
pub(crate) focus_handle: FocusHandle,
pub(crate) query_input: Entity<InputState>,
@ -447,6 +449,7 @@ where
.id(id)
.w_full()
.relative()
.overflow_hidden()
.children(self.delegate.render_item(ix, window, cx).map(|item| {
item.selected(selected)
.secondary_selected(mouse_right_clicked)
@ -483,13 +486,11 @@ where
let rows_cache = self.rows_cache.clone();
let scrollbar_visible = self.options.scrollbar_visible;
let scroll_handle = self.scroll_handle.clone();
let measured_size = rows_cache.measured_size();
v_flex()
.flex_grow()
.relative()
.h_full()
.min_w(measured_size.item_size.width)
.size_full()
.when_some(self.options.max_height, |this, h| this.max_h(h))
.overflow_hidden()
.when(items_count == 0, |this| {