Navigation · Tabs on_context: a right click on a tab reports that tab and the pointer, not the chosen one

This commit is contained in:
ZacharyZhang-NY committed 2026-10-04 15:53:30 -04:00
1 parent 64293a81af
commit 9977785de6
2 files changed
+63 -1

No files matched your search

+38
View File
@@ -470,3 +470,41 @@ fn steps_fill_a_column_their_block_measures_by_content(cx: &mut TestAppContext)
"the steps span the card inside its padding"
);
}
struct Context_ {
chosen: SharedString,
asked: Option<SharedString>,
}
impl Render for Context_ {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
let tabs = [Choice::new("a", "A"), Choice::new("c", "C")];
Tabs::new("tabs", tabs, self.chosen.clone()).on_context(move |value, _, _, cx| {
view.update(cx, |view, cx| {
view.asked = Some(value.clone());
cx.notify();
})
})
}
}
#[gpui::test]
fn a_right_click_names_its_tab_and_keeps_the_choice(cx: &mut TestAppContext) {
setup(cx);
let (view, cx) = cx.add_window_view(|_, _| Context_ {
chosen: "c".into(),
asked: None,
});
settle(cx);
let at = point(px(12.0), px(16.0));
cx.simulate_mouse_move(at, None, Modifiers::none());
cx.simulate_mouse_down(at, gpui::MouseButton::Right, Modifiers::none());
let (chosen, asked) = view.read_with(cx, |view, _| (view.chosen.clone(), view.asked.clone()));
assert_eq!(
asked.as_deref(),
Some("a"),
"the clicked tab, not the chosen one"
);
assert_eq!(chosen, "c");
}