Render match count next to branch label
This commit is contained in:
parent
7c2c1a279b
commit
525521eeb3
2 changed files with 58 additions and 45 deletions
|
@ -1,6 +1,8 @@
|
||||||
use anyhow::{anyhow, bail};
|
use anyhow::{anyhow, bail};
|
||||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
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 picker::{Picker, PickerDelegate, PickerEvent};
|
||||||
use std::{ops::Not, sync::Arc};
|
use std::{ops::Not, sync::Arc};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
@ -210,50 +212,55 @@ impl PickerDelegate for BranchListDelegate {
|
||||||
.with_height(theme.contact_finder.row_height)
|
.with_height(theme.contact_finder.row_height)
|
||||||
.into_any()
|
.into_any()
|
||||||
}
|
}
|
||||||
fn render_header(&self, cx: &AppContext) -> Option<AnyElement<Picker<Self>>> {
|
fn render_header(
|
||||||
|
&self,
|
||||||
|
cx: &mut ViewContext<Picker<Self>>,
|
||||||
|
) -> Option<AnyElement<Picker<Self>>> {
|
||||||
let theme = &theme::current(cx);
|
let theme = &theme::current(cx);
|
||||||
let style = theme.picker.header.clone();
|
let style = theme.picker.header.clone();
|
||||||
if self.last_query.is_empty() {
|
let label = if self.last_query.is_empty() {
|
||||||
Some(
|
Stack::new()
|
||||||
Stack::new()
|
.with_child(
|
||||||
.with_child(
|
Flex::row()
|
||||||
Flex::row()
|
.with_child(Label::new("Recent branches", style.label.clone()))
|
||||||
.with_child(Label::new("Recent branches", style.label.clone()))
|
.contained()
|
||||||
.contained()
|
.with_style(style.container)
|
||||||
.with_style(style.container)
|
.into_any(),
|
||||||
.into_any(),
|
)
|
||||||
)
|
.contained()
|
||||||
.contained()
|
.with_style(style.container)
|
||||||
.with_style(style.container)
|
.into_any()
|
||||||
.into_any(),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
Some(
|
Stack::new()
|
||||||
Stack::new()
|
.with_child(
|
||||||
.with_child(
|
Flex::row()
|
||||||
Flex::row()
|
.with_child(Label::new("Branches", style.label.clone()).aligned().left())
|
||||||
.with_child(
|
.contained()
|
||||||
Label::new("Branches", style.label.clone()).aligned().left(),
|
.with_style(style.container),
|
||||||
)
|
)
|
||||||
.contained()
|
.with_children(self.matches.is_empty().not().then(|| {
|
||||||
.with_style(style.container),
|
let suffix = if self.matches.len() == 1 { "" } else { "es" };
|
||||||
)
|
Flex::row()
|
||||||
.with_children(self.matches.is_empty().not().then(|| {
|
.align_children_center()
|
||||||
let suffix = if self.matches.len() == 1 { "" } else { "es" };
|
.with_child(Label::new(
|
||||||
Flex::row()
|
format!("{} match{}", self.matches.len(), suffix),
|
||||||
.align_children_center()
|
style.label,
|
||||||
.with_child(Label::new(
|
))
|
||||||
format!("{} match{}", self.matches.len(), suffix),
|
.aligned()
|
||||||
style.label,
|
.right()
|
||||||
))
|
}))
|
||||||
.aligned()
|
.contained()
|
||||||
.right()
|
.with_style(style.container)
|
||||||
}))
|
.constrained()
|
||||||
.contained()
|
.into_any()
|
||||||
.with_style(style.container)
|
};
|
||||||
.constrained()
|
Some(
|
||||||
.into_any(),
|
MouseEventHandler::<BranchList, _>::new(0, cx, move |_, _| label)
|
||||||
)
|
.on_click(MouseButton::Left, move |_, _, _| {})
|
||||||
}
|
.on_down_out(MouseButton::Left, move |_, _, cx| {
|
||||||
|
cx.emit(PickerEvent::Dismiss)
|
||||||
|
})
|
||||||
|
.into_any(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,10 +45,16 @@ pub trait PickerDelegate: Sized + 'static {
|
||||||
fn center_selection_after_match_updates(&self) -> bool {
|
fn center_selection_after_match_updates(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
fn render_header(&self, _cx: &AppContext) -> Option<AnyElement<Picker<Self>>> {
|
fn render_header(
|
||||||
|
&self,
|
||||||
|
_cx: &mut ViewContext<Picker<Self>>,
|
||||||
|
) -> Option<AnyElement<Picker<Self>>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn render_footer(&self, _cx: &AppContext) -> Option<AnyElement<Picker<Self>>> {
|
fn render_footer(
|
||||||
|
&self,
|
||||||
|
_cx: &mut ViewContext<Picker<Self>>,
|
||||||
|
) -> Option<AnyElement<Picker<Self>>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue