From 1096eeff3a428b41139cffbfb320ebe4f6fe1840 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 23 Dec 2023 22:33:52 +0200 Subject: [PATCH] Add a horizontal separator between history and query file finder matches --- crates/file_finder2/src/file_finder.rs | 9 +++++++++ crates/picker2/src/picker2.rs | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/file_finder2/src/file_finder.rs b/crates/file_finder2/src/file_finder.rs index 7410ed7658..8ca7d46f29 100644 --- a/crates/file_finder2/src/file_finder.rs +++ b/crates/file_finder2/src/file_finder.rs @@ -544,6 +544,15 @@ impl PickerDelegate for FileFinderDelegate { cx.notify(); } + fn separators_after_indices(&self) -> Vec { + 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, diff --git a/crates/picker2/src/picker2.rs b/crates/picker2/src/picker2.rs index 8585d9e73b..3abdf953b3 100644 --- a/crates/picker2/src/picker2.rs +++ b/crates/picker2/src/picker2.rs @@ -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 { @@ -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 { + Vec::new() + } fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext>); fn placeholder_text(&self) -> Arc; @@ -266,6 +269,7 @@ impl Render for Picker { "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 Render for Picker { ix, ix == selected_index, cx, - )) + )).when(separators_after_indices.contains(&ix), |picker| picker.child(ListSeparator)) }) .collect() }