From 8c948b0529ef301b7789cd04b1fb218c5f566249 Mon Sep 17 00:00:00 2001 From: Richard Nelson Date: Wed, 15 Jul 2026 17:02:37 +1000 Subject: [PATCH] Fix completion menu intrinsic width measurement --- crates/ui/src/list/list.rs | 4 ++++ crates/ui/src/virtual_list.rs | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/ui/src/list/list.rs b/crates/ui/src/list/list.rs index 8016c3d649..a70456fd70 100644 --- a/crates/ui/src/list/list.rs +++ b/crates/ui/src/list/list.rs @@ -510,6 +510,9 @@ where let rows_cache = self.rows_cache.clone(); let scrollbar_visible = self.options.scrollbar_visible; let scroll_handle = self.scroll_handle.clone(); + let item_to_measure_index = rows_cache + .position_of(&self.item_to_measure_index) + .unwrap_or(0); v_flex() .flex_grow_1() @@ -563,6 +566,7 @@ where .collect::>() }, ) + .with_item_to_measure_index(item_to_measure_index) .paddings(self.options.paddings.clone()) .when(self.options.max_height.is_some(), |this| { this.with_sizing_behavior(ListSizingBehavior::Infer) diff --git a/crates/ui/src/virtual_list.rs b/crates/ui/src/virtual_list.rs index 8f2cfffc1c..423a1280c5 100644 --- a/crates/ui/src/virtual_list.rs +++ b/crates/ui/src/virtual_list.rs @@ -124,8 +124,9 @@ impl VirtualListScrollHandle { /// /// This is like `uniform_list` in GPUI, but support two axis. /// -/// The `item_sizes` is the size of each column, -/// only the `height` is used, `width` is ignored and VirtualList will measure the first item width. +/// The `item_sizes` is the size of each row. Only the `height` is used; `width` is inferred +/// by measuring the item selected with [`VirtualList::with_item_to_measure_index`], defaulting +/// to the first item. /// /// See also [`h_virtual_list`] #[inline] @@ -197,6 +198,7 @@ where item_sizes, render_items: Box::new(render_range), sizing_behavior: ListSizingBehavior::default(), + item_to_measure_index: 0, } } @@ -212,6 +214,7 @@ pub struct VirtualList { dyn for<'a> Fn(Range, &'a mut Window, &'a mut App) -> SmallVec<[AnyElement; 64]>, >, sizing_behavior: ListSizingBehavior, + item_to_measure_index: usize, } impl Styled for VirtualList { @@ -233,6 +236,12 @@ impl VirtualList { self } + /// Set the item index used to infer the list's cross-axis size. + pub fn with_item_to_measure_index(mut self, index: usize) -> Self { + self.item_to_measure_index = index; + self + } + /// Specify for table. /// /// Table is special, because the `scroll_handle` is based on Table head (That is not a virtual list). @@ -301,7 +310,7 @@ impl VirtualList { return Size::default(); } - let item_ix = 0; + let item_ix = self.item_to_measure_index.min(self.items_count - 1); let mut items = (self.render_items)(item_ix..item_ix + 1, window, cx); let Some(mut item_to_measure) = items.pop() else { return Size::default();