From 7d704d97f40a9d47c08891c35d7dbe26a2220e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Sun, 18 Oct 2026 22:10:52 -0400 Subject: [PATCH] Navigation: a long tab fits its strip and cuts its label Co-Authored-By: Claude --- src/navigation/tabs.rs | 6 +++++- src/navigation/tests/tabs.rs | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/navigation/tabs.rs b/src/navigation/tabs.rs index e1b78f0..364cb24 100644 --- a/src/navigation/tabs.rs +++ b/src/navigation/tabs.rs @@ -182,6 +182,7 @@ impl RenderOnce for Tabs { let value = tab.value.clone(); div() .id(("tab", ix)) + .debug_selector(move || format!("tab-{ix}")) .role(Role::Tab) .aria_selected(on) .aria_label(tab.label.clone()) @@ -231,7 +232,10 @@ impl RenderOnce for Tabs { .when(compact, |item| { item.tooltip(Tooltip::text(tab.label.clone())) }) - .when(!compact, |item| item.child(tab.label.clone())) + .when(axis == Axis::Horizontal, |item| item.max_w_full()) + .when(!compact, |item| { + item.child(div().min_w_0().truncate().child(tab.label.clone())) + }) .when_some(tab.note.clone().filter(|_| !compact), |item, note| { item.child(div().text_color(colors.fg_subtle).child(note)) }) diff --git a/src/navigation/tests/tabs.rs b/src/navigation/tests/tabs.rs index 91f686b..dec8600 100644 --- a/src/navigation/tests/tabs.rs +++ b/src/navigation/tests/tabs.rs @@ -185,12 +185,14 @@ struct Sheets { chosen: SharedString, clicked: Option, width: f32, + long: bool, } impl Render for Sheets { fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl IntoElement { let view = cx.entity(); - let tabs = (0..30).map(|ix| Choice::new(format!("s{ix}"), format!("Sheet {ix}"))); + let tail = if self.long { "W".repeat(40) } else { String::new() }; + let tabs = (0..30).map(|ix| Choice::new(format!("s{ix}"), format!("Sheet {ix}{tail}"))); div() .w(px(self.width)) .child( @@ -218,6 +220,7 @@ fn a_wide_strip_scrolls_its_chosen_tab_in_and_the_wheel_reaches_the_rest(cx: &mu chosen: "s29".into(), clicked: None, width: 300.0, + long: false, }); settle(cx); assert!( @@ -252,6 +255,7 @@ fn a_strip_that_narrows_keeps_its_chosen_tab_in_view(cx: &mut TestAppContext) { chosen: "s29".into(), clicked: None, width: 700.0, + long: false, }); settle(cx); view.update(cx, |view, cx| { @@ -265,3 +269,18 @@ fn a_strip_that_narrows_keeps_its_chosen_tab_in_view(cx: &mut TestAppContext) { let clicked = view.read_with(cx, |view, _| view.clicked.clone()); assert_eq!(clicked, None, "the chosen tab ends the strip"); } + +#[gpui::test] +fn a_long_chosen_tab_fits_the_strip(cx: &mut TestAppContext) { + setup(cx); + let (_view, cx) = cx.add_window_view(|_, _| Sheets { + chosen: "s29".into(), + clicked: None, + width: 250.0, + long: true, + }); + settle(cx); + let tab = cx.debug_bounds("tab-29").expect("the chosen tab"); + assert!(tab.left() >= px(0.0), "starts in view: {tab:?}"); + assert!(tab.right() <= px(250.0), "ends in view: {tab:?}"); +}