@@ -114,7 +114,7 @@ impl Preview<'_, '_> {
117−pub struct FilePicker<T: Item> {
117+pub struct Picker<T: Item> {
118 options: Vec<T>,
118 options: Vec<T>,
119 editor_data: T::Data,
119 editor_data: T::Data,
120 // filter: String,
120 // filter: String,
@@ -135,7 +135,6 @@ pub struct FilePicker<T: Item> {
136 callback_fn: PickerCallback<T>,
136 callback_fn: PickerCallback<T>,
139 pub truncate_start: bool,
138 pub truncate_start: bool,
140 /// Caches paths to documents
139 /// Caches paths to documents
141 preview_cache: HashMap<PathBuf, CachedPreview>,
140 preview_cache: HashMap<PathBuf, CachedPreview>,
@@ -144,7 +143,7 @@ pub struct FilePicker<T: Item> {
144 file_fn: Option<FileCallback<T>>,
143 file_fn: Option<FileCallback<T>>,
147−impl<T: Item + 'static> FilePicker<T> {
146+impl<T: Item + 'static> Picker<T> {
148 pub fn new(
147 pub fn new(
149 options: Vec<T>,
148 options: Vec<T>,
150 editor_data: T::Data,
149 editor_data: T::Data,
@@ -173,8 +172,6 @@ impl<T: Item + 'static> FilePicker<T> {
173 preview_cache: HashMap::new(),
172 preview_cache: HashMap::new(),
174 read_buffer: Vec::with_capacity(1024),
173 read_buffer: Vec::with_capacity(1024),
175 file_fn: None,
174 file_fn: None,
177− picker: unimplemented!(),
180 picker.calculate_column_widths();
177 picker.calculate_column_widths();
@@ -197,7 +194,6 @@ impl<T: Item + 'static> FilePicker<T> {
198 pub fn truncate_start(mut self, truncate_start: bool) -> Self {
195 pub fn truncate_start(mut self, truncate_start: bool) -> Self {
199 self.truncate_start = truncate_start;
196 self.truncate_start = truncate_start;
200− self.picker.truncate_start = truncate_start;
@@ -377,8 +373,7 @@ impl<T: Item + 'static> FilePicker<T> {
379 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
375 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
381− .selection()
376+ self.selection()
382 .and_then(|current| (self.file_fn.as_ref()?)(editor, current))
377 .and_then(|current| (self.file_fn.as_ref()?)(editor, current))
383 .and_then(|(path_or_id, line)| path_or_id.get_canonicalized().ok().zip(Some(line)))
378 .and_then(|(path_or_id, line)| path_or_id.get_canonicalized().ok().zip(Some(line)))
@@ -849,13 +844,9 @@ impl<T: Item + 'static> FilePicker<T> {
849 self.completion_height = height.saturating_sub(4);
844 self.completion_height = height.saturating_sub(4);
850 Some((width, height))
845 Some((width, height))
853− fn id(&self) -> Option<&'static str> {
858−impl<T: Item + 'static> Component for FilePicker<T> {
849+impl<T: Item + 'static> Component for Picker<T> {
859 fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
850 fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
860 // +---------+ +---------+
851 // +---------+ +---------+
861 // |prompt | |preview |
852 // |prompt | |preview |
@@ -864,7 +855,7 @@ impl<T: Item + 'static> Component for FilePicker<T> {
864 // | | | |
855 // | | | |
865 // +---------+ +---------+
856 // +---------+ +---------+
867− let render_preview = self.picker.show_preview && area.width > MIN_AREA_WIDTH_FOR_PREVIEW;
858+ let render_preview = self.show_preview && area.width > MIN_AREA_WIDTH_FOR_PREVIEW;
869 let picker_width = if render_preview {
860 let picker_width = if render_preview {
870 area.width / 2
861 area.width / 2
@@ -909,112 +900,6 @@ impl Ord for PickerMatch {
910type PickerCallback<T> = Box<dyn Fn(&mut Context, &T, Action)>;
901type PickerCallback<T> = Box<dyn Fn(&mut Context, &T, Action)>;
912−pub struct Picker<T: Item> {
914− editor_data: T::Data,
916− matcher: Box<Matcher>,
917− matches: Vec<PickerMatch>,
919− /// Current height of the completions box
920− completion_height: u16,
925− previous_pattern: (String, FuzzyQuery),
926− /// Whether to truncate the start (default true)
927− pub truncate_start: bool,
928− /// Whether to show the preview panel (default true)
930− /// Constraints for tabular formatting
931− widths: Vec<Constraint>,
933− callback_fn: PickerCallback<T>,
936−impl<T: Item> Picker<T> {
939− editor_data: T::Data,
940− callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
945− pub fn set_options(&mut self, new_options: Vec<T>) {
949− pub fn score(&mut self) {
953− pub fn force_score(&mut self) {
957− /// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`)
958− pub fn move_by(&mut self, amount: usize, direction: Direction) {
962− /// Move the cursor down by exactly one page. After the last page comes the first page.
963− pub fn page_up(&mut self) {
967− /// Move the cursor up by exactly one page. After the first page comes the last page.
968− pub fn page_down(&mut self) {
972− /// Move the cursor to the first entry
973− pub fn to_start(&mut self) {
977− /// Move the cursor to the last entry
978− pub fn to_end(&mut self) {
982− pub fn selection(&self) -> Option<&T> {
986− pub fn toggle_preview(&mut self) {
990− fn prompt_handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
996−// - read all the files into a list, maxed out at a large value
997−// - on input change:
998−// - score all the names in relation to input
1000−impl<T: Item + 'static> Component for Picker<T> {
1001− fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
1005− fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
1009− fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
1013− fn cursor(&self, area: Rect, editor: &Editor) -> (Option<Position>, CursorKind) {
1018/// Returns a new list of options to replace the contents of the picker
903/// Returns a new list of options to replace the contents of the picker
1019/// when called with the current picker query,
904/// when called with the current picker query,
1020pub type DynQueryCallback<T> =
905pub type DynQueryCallback<T> =
@@ -1023,7 +908,7 @@ pub type DynQueryCallback<T> =
1023/// A picker that updates its contents via a callback whenever the
908/// A picker that updates its contents via a callback whenever the
1024/// query string changes. Useful for live grep, workspace symbols, etc.
909/// query string changes. Useful for live grep, workspace symbols, etc.
1025pub struct DynamicPicker<T: ui::menu::Item + Send> {
910pub struct DynamicPicker<T: ui::menu::Item + Send> {
1026− file_picker: FilePicker<T>,
911+ file_picker: Picker<T>,
1027 query_callback: DynQueryCallback<T>,
912 query_callback: DynQueryCallback<T>,
1028 query: String,
913 query: String,
@@ -1031,7 +916,7 @@ pub struct DynamicPicker<T: ui::menu::Item + Send> {
1031impl<T: ui::menu::Item + Send> DynamicPicker<T> {
916impl<T: ui::menu::Item + Send> DynamicPicker<T> {
1032 pub const ID: &'static str = "dynamic-picker";
917 pub const ID: &'static str = "dynamic-picker";
1034− pub fn new(file_picker: FilePicker<T>, query_callback: DynQueryCallback<T>) -> Self {
919+ pub fn new(file_picker: Picker<T>, query_callback: DynQueryCallback<T>) -> Self {
1036 file_picker,
921 file_picker,
1037 query_callback,
922 query_callback,
@@ -1047,7 +932,7 @@ impl<T: Item + Send + 'static> Component for DynamicPicker<T> {
1048 fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
933 fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
1049 let event_result = self.file_picker.handle_event(event, cx);
934 let event_result = self.file_picker.handle_event(event, cx);
1050− let current_query = self.file_picker.picker.prompt.line();
935+ let current_query = self.file_picker.prompt.line();
1052 if !matches!(event, Event::IdleTimeout) || self.query == *current_query {
937 if !matches!(event, Event::IdleTimeout) || self.query == *current_query {
1053 return event_result;
938 return event_result;
@@ -1063,7 +948,7 @@ impl<T: Item + Send + 'static> Component for DynamicPicker<T> {
1063 // Wrapping of pickers in overlay is done outside the picker code,
948 // Wrapping of pickers in overlay is done outside the picker code,
1064 // so this is fragile and will break if wrapped in some other widget.
949 // so this is fragile and will break if wrapped in some other widget.
1065 let picker = match compositor.find_id::<Overlay<DynamicPicker<T>>>(Self::ID) {
950 let picker = match compositor.find_id::<Overlay<DynamicPicker<T>>>(Self::ID) {
1066− Some(overlay) => &mut overlay.content.file_picker.picker,
951+ Some(overlay) => &mut overlay.content.file_picker,
1067 None => return,
952 None => return,
1069 picker.set_options(new_options);
954 picker.set_options(new_options);