diff --git a/crates/collab_ui/src/branch_list.rs b/crates/collab_ui/src/branch_list.rs index 0abe83f766..8c06326780 100644 --- a/crates/collab_ui/src/branch_list.rs +++ b/crates/collab_ui/src/branch_list.rs @@ -1,6 +1,8 @@ use anyhow::{anyhow, bail}; use fuzzy::{StringMatch, StringMatchCandidate}; -use gpui::{elements::*, AppContext, MouseState, Task, ViewContext, ViewHandle}; +use gpui::{ + elements::*, platform::MouseButton, AppContext, MouseState, Task, ViewContext, ViewHandle, +}; use picker::{Picker, PickerDelegate, PickerEvent}; use std::{ops::Not, sync::Arc}; use util::ResultExt; @@ -210,50 +212,55 @@ impl PickerDelegate for BranchListDelegate { .with_height(theme.contact_finder.row_height) .into_any() } - fn render_header(&self, cx: &AppContext) -> Option>> { + fn render_header( + &self, + cx: &mut ViewContext>, + ) -> Option>> { let theme = &theme::current(cx); let style = theme.picker.header.clone(); - if self.last_query.is_empty() { - Some( - Stack::new() - .with_child( - Flex::row() - .with_child(Label::new("Recent branches", style.label.clone())) - .contained() - .with_style(style.container) - .into_any(), - ) - .contained() - .with_style(style.container) - .into_any(), - ) + let label = if self.last_query.is_empty() { + Stack::new() + .with_child( + Flex::row() + .with_child(Label::new("Recent branches", style.label.clone())) + .contained() + .with_style(style.container) + .into_any(), + ) + .contained() + .with_style(style.container) + .into_any() } else { - Some( - Stack::new() - .with_child( - Flex::row() - .with_child( - Label::new("Branches", style.label.clone()).aligned().left(), - ) - .contained() - .with_style(style.container), - ) - .with_children(self.matches.is_empty().not().then(|| { - let suffix = if self.matches.len() == 1 { "" } else { "es" }; - Flex::row() - .align_children_center() - .with_child(Label::new( - format!("{} match{}", self.matches.len(), suffix), - style.label, - )) - .aligned() - .right() - })) - .contained() - .with_style(style.container) - .constrained() - .into_any(), - ) - } + Stack::new() + .with_child( + Flex::row() + .with_child(Label::new("Branches", style.label.clone()).aligned().left()) + .contained() + .with_style(style.container), + ) + .with_children(self.matches.is_empty().not().then(|| { + let suffix = if self.matches.len() == 1 { "" } else { "es" }; + Flex::row() + .align_children_center() + .with_child(Label::new( + format!("{} match{}", self.matches.len(), suffix), + style.label, + )) + .aligned() + .right() + })) + .contained() + .with_style(style.container) + .constrained() + .into_any() + }; + Some( + MouseEventHandler::::new(0, cx, move |_, _| label) + .on_click(MouseButton::Left, move |_, _, _| {}) + .on_down_out(MouseButton::Left, move |_, _, cx| { + cx.emit(PickerEvent::Dismiss) + }) + .into_any(), + ) } } diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index 33d6e84241..978d018ccf 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -45,10 +45,16 @@ pub trait PickerDelegate: Sized + 'static { fn center_selection_after_match_updates(&self) -> bool { false } - fn render_header(&self, _cx: &AppContext) -> Option>> { + fn render_header( + &self, + _cx: &mut ViewContext>, + ) -> Option>> { None } - fn render_footer(&self, _cx: &AppContext) -> Option>> { + fn render_footer( + &self, + _cx: &mut ViewContext>, + ) -> Option>> { None } }