Add a horizontal separator between history and query file finder matches
This commit is contained in:
parent
1f603afbc1
commit
1096eeff3a
2 changed files with 15 additions and 2 deletions
|
@ -544,6 +544,15 @@ impl PickerDelegate for FileFinderDelegate {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn separators_after_indices(&self) -> Vec<usize> {
|
||||||
|
let history_items = self.matches.history.len();
|
||||||
|
if history_items == 0 {
|
||||||
|
Vec::new()
|
||||||
|
} else {
|
||||||
|
vec![history_items - 1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn update_matches(
|
fn update_matches(
|
||||||
&mut self,
|
&mut self,
|
||||||
raw_query: String,
|
raw_query: String,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use gpui::{
|
||||||
UniformListScrollHandle, View, ViewContext, WindowContext,
|
UniformListScrollHandle, View, ViewContext, WindowContext,
|
||||||
};
|
};
|
||||||
use std::{cmp, sync::Arc};
|
use std::{cmp, sync::Arc};
|
||||||
use ui::{prelude::*, v_stack, Color, Divider, Label, ListItem, ListItemSpacing};
|
use ui::{prelude::*, v_stack, Color, Divider, Label, ListItem, ListItemSpacing, ListSeparator};
|
||||||
use workspace::ModalView;
|
use workspace::ModalView;
|
||||||
|
|
||||||
pub struct Picker<D: PickerDelegate> {
|
pub struct Picker<D: PickerDelegate> {
|
||||||
|
@ -26,6 +26,9 @@ pub trait PickerDelegate: Sized + 'static {
|
||||||
type ListItem: IntoElement;
|
type ListItem: IntoElement;
|
||||||
fn match_count(&self) -> usize;
|
fn match_count(&self) -> usize;
|
||||||
fn selected_index(&self) -> usize;
|
fn selected_index(&self) -> usize;
|
||||||
|
fn separators_after_indices(&self) -> Vec<usize> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>);
|
fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>);
|
||||||
|
|
||||||
fn placeholder_text(&self) -> Arc<str>;
|
fn placeholder_text(&self) -> Arc<str>;
|
||||||
|
@ -266,6 +269,7 @@ impl<D: PickerDelegate> Render for Picker<D> {
|
||||||
"candidates",
|
"candidates",
|
||||||
self.delegate.match_count(),
|
self.delegate.match_count(),
|
||||||
{
|
{
|
||||||
|
let separators_after_indices = self.delegate.separators_after_indices();
|
||||||
let selected_index = self.delegate.selected_index();
|
let selected_index = self.delegate.selected_index();
|
||||||
move |picker, visible_range, cx| {
|
move |picker, visible_range, cx| {
|
||||||
visible_range
|
visible_range
|
||||||
|
@ -285,7 +289,7 @@ impl<D: PickerDelegate> Render for Picker<D> {
|
||||||
ix,
|
ix,
|
||||||
ix == selected_index,
|
ix == selected_index,
|
||||||
cx,
|
cx,
|
||||||
))
|
)).when(separators_after_indices.contains(&ix), |picker| picker.child(ListSeparator))
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue