Avoid showing "No matches" when query is empty if there are no matches

This commit is contained in:
Antonio Scandurra 2022-11-03 15:23:35 +01:00
parent aec8aec800
commit 08b84416d2
5 changed files with 93 additions and 59 deletions

View file

@ -1,14 +1,11 @@
use editor::Editor;
use gpui::{
elements::{
ChildView, Flex, Label, MouseEventHandler, ParentElement, ScrollTarget, UniformList,
UniformListState,
},
elements::*,
geometry::vector::{vec2f, Vector2F},
keymap,
platform::CursorStyle,
AnyViewHandle, AppContext, Axis, Element, ElementBox, Entity, MouseButton, MouseState,
MutableAppContext, RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
AnyViewHandle, AppContext, Axis, Entity, MouseButton, MouseState, MutableAppContext,
RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
};
use menu::{Cancel, Confirm, SelectFirst, SelectIndex, SelectLast, SelectNext, SelectPrev};
use settings::Settings;
@ -53,7 +50,7 @@ impl<D: PickerDelegate> View for Picker<D> {
fn render(&mut self, cx: &mut RenderContext<Self>) -> gpui::ElementBox {
let theme = (self.theme)(cx);
let container_style = theme.container;
let query = self.query(cx);
let delegate = self.delegate.clone();
let match_count = if let Some(delegate) = delegate.upgrade(cx.app) {
delegate.read(cx).match_count()
@ -61,19 +58,36 @@ impl<D: PickerDelegate> View for Picker<D> {
0
};
let container_style;
let editor_style;
if query.is_empty() && match_count == 0 {
container_style = theme.empty_container;
editor_style = theme.empty_input_editor.container;
} else {
container_style = theme.container;
editor_style = theme.input_editor.container;
};
Flex::new(Axis::Vertical)
.with_child(
ChildView::new(&self.query_editor, cx)
.contained()
.with_style(theme.input_editor.container)
.with_style(editor_style)
.boxed(),
)
.with_child(
if match_count == 0 {
Label::new("No matches".into(), theme.empty.label.clone())
.contained()
.with_style(theme.empty.container)
.with_children(if match_count == 0 {
if query.is_empty() {
None
} else {
Some(
Label::new("No matches".into(), theme.no_matches.label.clone())
.contained()
.with_style(theme.no_matches.container)
.boxed(),
)
}
} else {
Some(
UniformList::new(
self.list_state.clone(),
match_count,
@ -98,10 +112,10 @@ impl<D: PickerDelegate> View for Picker<D> {
)
.contained()
.with_margin_top(6.0)
}
.flex(1., false)
.boxed(),
)
.flex(1., false)
.boxed(),
)
})
.contained()
.with_style(container_style)
.constrained()