Add a horizontal separator between history and query file finder matches (#3808)

To avoid confusion with the way file results are matched, add a
separator between history and query matches in file finders.

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov
2023-12-23 23:23:49 +02:00
committed by GitHub
2 changed files with 15 additions and 2 deletions
+9
View File
@@ -544,6 +544,15 @@ impl PickerDelegate for FileFinderDelegate {
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(
&mut self,
raw_query: String,
+6 -2
View File
@@ -5,7 +5,7 @@ use gpui::{
UniformListScrollHandle, View, ViewContext, WindowContext,
};
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;
pub struct Picker<D: PickerDelegate> {
@@ -26,6 +26,9 @@ pub trait PickerDelegate: Sized + 'static {
type ListItem: IntoElement;
fn match_count(&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 placeholder_text(&self) -> Arc<str>;
@@ -266,6 +269,7 @@ impl<D: PickerDelegate> Render for Picker<D> {
"candidates",
self.delegate.match_count(),
{
let separators_after_indices = self.delegate.separators_after_indices();
let selected_index = self.delegate.selected_index();
move |picker, visible_range, cx| {
visible_range
@@ -285,7 +289,7 @@ impl<D: PickerDelegate> Render for Picker<D> {
ix,
ix == selected_index,
cx,
))
)).when(separators_after_indices.contains(&ix), |picker| picker.child(ListSeparator))
})
.collect()
}