picker.rs

  1use anyhow::Result;
  2use editor::{scroll::Autoscroll, Editor};
  3use gpui::{
  4    actions, div, impl_actions, list, prelude::*, uniform_list, AnyElement, App, ClickEvent,
  5    Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Length,
  6    ListSizingBehavior, ListState, MouseButton, MouseUpEvent, Render, ScrollStrategy, Task,
  7    UniformListScrollHandle, Window,
  8};
  9use head::Head;
 10use schemars::JsonSchema;
 11use serde::Deserialize;
 12use std::{sync::Arc, time::Duration};
 13use ui::{prelude::*, v_flex, Color, Divider, Label, ListItem, ListItemSpacing};
 14use workspace::ModalView;
 15
 16mod head;
 17pub mod highlighted_match_with_paths;
 18
 19enum ElementContainer {
 20    List(ListState),
 21    UniformList(UniformListScrollHandle),
 22}
 23
 24actions!(picker, [ConfirmCompletion]);
 25
 26/// ConfirmInput is an alternative editor action which - instead of selecting active picker entry - treats pickers editor input literally,
 27/// performing some kind of action on it.
 28#[derive(Clone, PartialEq, Deserialize, JsonSchema, Default)]
 29#[serde(deny_unknown_fields)]
 30pub struct ConfirmInput {
 31    pub secondary: bool,
 32}
 33
 34impl_actions!(picker, [ConfirmInput]);
 35
 36struct PendingUpdateMatches {
 37    delegate_update_matches: Option<Task<()>>,
 38    _task: Task<Result<()>>,
 39}
 40
 41pub struct Picker<D: PickerDelegate> {
 42    pub delegate: D,
 43    element_container: ElementContainer,
 44    head: Head,
 45    pending_update_matches: Option<PendingUpdateMatches>,
 46    confirm_on_update: Option<bool>,
 47    width: Option<Length>,
 48    max_height: Option<Length>,
 49
 50    /// Whether the `Picker` is rendered as a self-contained modal.
 51    ///
 52    /// Set this to `false` when rendering the `Picker` as part of a larger modal.
 53    is_modal: bool,
 54}
 55
 56#[derive(Debug, Default, Clone, Copy, PartialEq)]
 57pub enum PickerEditorPosition {
 58    #[default]
 59    /// Render the editor at the start of the picker. Usually the top
 60    Start,
 61    /// Render the editor at the end of the picker. Usually the bottom
 62    End,
 63}
 64
 65pub trait PickerDelegate: Sized + 'static {
 66    type ListItem: IntoElement;
 67
 68    fn match_count(&self) -> usize;
 69    fn selected_index(&self) -> usize;
 70    fn separators_after_indices(&self) -> Vec<usize> {
 71        Vec::new()
 72    }
 73    fn set_selected_index(
 74        &mut self,
 75        ix: usize,
 76        window: &mut Window,
 77        cx: &mut Context<Picker<Self>>,
 78    );
 79    // Allows binding some optional effect to when the selection changes.
 80    fn selected_index_changed(
 81        &self,
 82        _ix: usize,
 83        _window: &mut Window,
 84        _cx: &mut Context<Picker<Self>>,
 85    ) -> Option<Box<dyn Fn(&mut Window, &mut App) + 'static>> {
 86        None
 87    }
 88    fn placeholder_text(&self, _window: &mut Window, _cx: &mut App) -> Arc<str>;
 89    fn no_matches_text(&self, _window: &mut Window, _cx: &mut App) -> SharedString {
 90        "No matches".into()
 91    }
 92    fn update_matches(
 93        &mut self,
 94        query: String,
 95        window: &mut Window,
 96        cx: &mut Context<Picker<Self>>,
 97    ) -> Task<()>;
 98
 99    // Delegates that support this method (e.g. the CommandPalette) can chose to block on any background
100    // work for up to `duration` to try and get a result synchronously.
101    // This avoids a flash of an empty command-palette on cmd-shift-p, and lets workspace::SendKeystrokes
102    // mostly work when dismissing a palette.
103    fn finalize_update_matches(
104        &mut self,
105        _query: String,
106        _duration: Duration,
107        _window: &mut Window,
108        _cx: &mut Context<Picker<Self>>,
109    ) -> bool {
110        false
111    }
112
113    /// Override if you want to have <enter> update the query instead of confirming.
114    fn confirm_update_query(
115        &mut self,
116        _window: &mut Window,
117        _cx: &mut Context<Picker<Self>>,
118    ) -> Option<String> {
119        None
120    }
121    fn confirm(&mut self, secondary: bool, window: &mut Window, cx: &mut Context<Picker<Self>>);
122    /// Instead of interacting with currently selected entry, treats editor input literally,
123    /// performing some kind of action on it.
124    fn confirm_input(
125        &mut self,
126        _secondary: bool,
127        _window: &mut Window,
128        _: &mut Context<Picker<Self>>,
129    ) {
130    }
131    fn dismissed(&mut self, window: &mut Window, cx: &mut Context<Picker<Self>>);
132    fn should_dismiss(&self) -> bool {
133        true
134    }
135    fn confirm_completion(
136        &mut self,
137        _query: String,
138        _window: &mut Window,
139        _: &mut Context<Picker<Self>>,
140    ) -> Option<String> {
141        None
142    }
143
144    fn editor_position(&self) -> PickerEditorPosition {
145        PickerEditorPosition::default()
146    }
147
148    fn render_editor(
149        &self,
150        editor: &Entity<Editor>,
151        _window: &mut Window,
152        _cx: &mut Context<Picker<Self>>,
153    ) -> Div {
154        v_flex()
155            .when(
156                self.editor_position() == PickerEditorPosition::End,
157                |this| this.child(Divider::horizontal()),
158            )
159            .child(
160                h_flex()
161                    .overflow_hidden()
162                    .flex_none()
163                    .h_9()
164                    .px_3()
165                    .child(editor.clone()),
166            )
167            .when(
168                self.editor_position() == PickerEditorPosition::Start,
169                |this| this.child(Divider::horizontal()),
170            )
171    }
172
173    fn render_match(
174        &self,
175        ix: usize,
176        selected: bool,
177        window: &mut Window,
178        cx: &mut Context<Picker<Self>>,
179    ) -> Option<Self::ListItem>;
180    fn render_header(
181        &self,
182        _window: &mut Window,
183        _: &mut Context<Picker<Self>>,
184    ) -> Option<AnyElement> {
185        None
186    }
187    fn render_footer(
188        &self,
189        _window: &mut Window,
190        _: &mut Context<Picker<Self>>,
191    ) -> Option<AnyElement> {
192        None
193    }
194}
195
196impl<D: PickerDelegate> Focusable for Picker<D> {
197    fn focus_handle(&self, cx: &App) -> FocusHandle {
198        match &self.head {
199            Head::Editor(editor) => editor.focus_handle(cx),
200            Head::Empty(head) => head.focus_handle(cx),
201        }
202    }
203}
204
205#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
206enum ContainerKind {
207    List,
208    UniformList,
209}
210
211impl<D: PickerDelegate> Picker<D> {
212    /// A picker, which displays its matches using `gpui::uniform_list`, all matches should have the same height.
213    /// The picker allows the user to perform search items by text.
214    /// If `PickerDelegate::render_match` can return items with different heights, use `Picker::list`.
215    pub fn uniform_list(delegate: D, window: &mut Window, cx: &mut Context<Self>) -> Self {
216        let head = Head::editor(
217            delegate.placeholder_text(window, cx),
218            Self::on_input_editor_event,
219            window,
220            cx,
221        );
222
223        Self::new(delegate, ContainerKind::UniformList, head, window, cx)
224    }
225
226    /// A picker, which displays its matches using `gpui::uniform_list`, all matches should have the same height.
227    /// If `PickerDelegate::render_match` can return items with different heights, use `Picker::list`.
228    pub fn nonsearchable_uniform_list(
229        delegate: D,
230        window: &mut Window,
231        cx: &mut Context<Self>,
232    ) -> Self {
233        let head = Head::empty(Self::on_empty_head_blur, window, cx);
234
235        Self::new(delegate, ContainerKind::UniformList, head, window, cx)
236    }
237
238    /// A picker, which displays its matches using `gpui::list`, matches can have different heights.
239    /// The picker allows the user to perform search items by text.
240    /// If `PickerDelegate::render_match` only returns items with the same height, use `Picker::uniform_list` as its implementation is optimized for that.
241    pub fn list(delegate: D, window: &mut Window, cx: &mut Context<Self>) -> Self {
242        let head = Head::editor(
243            delegate.placeholder_text(window, cx),
244            Self::on_input_editor_event,
245            window,
246            cx,
247        );
248
249        Self::new(delegate, ContainerKind::List, head, window, cx)
250    }
251
252    fn new(
253        delegate: D,
254        container: ContainerKind,
255        head: Head,
256        window: &mut Window,
257        cx: &mut Context<Self>,
258    ) -> Self {
259        let mut this = Self {
260            delegate,
261            head,
262            element_container: Self::create_element_container(container, cx),
263            pending_update_matches: None,
264            confirm_on_update: None,
265            width: None,
266            max_height: Some(rems(18.).into()),
267            is_modal: true,
268        };
269        this.update_matches("".to_string(), window, cx);
270        // give the delegate 4ms to render the first set of suggestions.
271        this.delegate
272            .finalize_update_matches("".to_string(), Duration::from_millis(4), window, cx);
273        this
274    }
275
276    fn create_element_container(
277        container: ContainerKind,
278        cx: &mut Context<Self>,
279    ) -> ElementContainer {
280        match container {
281            ContainerKind::UniformList => {
282                ElementContainer::UniformList(UniformListScrollHandle::new())
283            }
284            ContainerKind::List => {
285                let entity = cx.entity().downgrade();
286                ElementContainer::List(ListState::new(
287                    0,
288                    gpui::ListAlignment::Top,
289                    px(1000.),
290                    move |ix, window, cx| {
291                        entity
292                            .upgrade()
293                            .map(|entity| {
294                                entity.update(cx, |this, cx| {
295                                    this.render_element(window, cx, ix).into_any_element()
296                                })
297                            })
298                            .unwrap_or_else(|| div().into_any_element())
299                    },
300                ))
301            }
302        }
303    }
304
305    pub fn width(mut self, width: impl Into<gpui::Length>) -> Self {
306        self.width = Some(width.into());
307        self
308    }
309
310    pub fn max_height(mut self, max_height: Option<gpui::Length>) -> Self {
311        self.max_height = max_height;
312        self
313    }
314
315    pub fn modal(mut self, modal: bool) -> Self {
316        self.is_modal = modal;
317        self
318    }
319
320    pub fn focus(&self, window: &mut Window, cx: &mut App) {
321        self.focus_handle(cx).focus(window);
322    }
323
324    /// Handles the selecting an index, and passing the change to the delegate.
325    /// If `scroll_to_index` is true, the new selected index will be scrolled into view.
326    ///
327    /// If some effect is bound to `selected_index_changed`, it will be executed.
328    pub fn set_selected_index(
329        &mut self,
330        ix: usize,
331        scroll_to_index: bool,
332        window: &mut Window,
333        cx: &mut Context<Self>,
334    ) {
335        let previous_index = self.delegate.selected_index();
336        self.delegate.set_selected_index(ix, window, cx);
337        let current_index = self.delegate.selected_index();
338
339        if previous_index != current_index {
340            if let Some(action) = self.delegate.selected_index_changed(ix, window, cx) {
341                action(window, cx);
342            }
343            if scroll_to_index {
344                self.scroll_to_item_index(ix);
345            }
346        }
347    }
348
349    pub fn select_next(
350        &mut self,
351        _: &menu::SelectNext,
352        window: &mut Window,
353        cx: &mut Context<Self>,
354    ) {
355        let count = self.delegate.match_count();
356        if count > 0 {
357            let index = self.delegate.selected_index();
358            let ix = if index == count - 1 { 0 } else { index + 1 };
359            self.set_selected_index(ix, true, window, cx);
360            cx.notify();
361        }
362    }
363
364    fn select_prev(&mut self, _: &menu::SelectPrev, window: &mut Window, cx: &mut Context<Self>) {
365        let count = self.delegate.match_count();
366        if count > 0 {
367            let index = self.delegate.selected_index();
368            let ix = if index == 0 { count - 1 } else { index - 1 };
369            self.set_selected_index(ix, true, window, cx);
370            cx.notify();
371        }
372    }
373
374    fn select_first(&mut self, _: &menu::SelectFirst, window: &mut Window, cx: &mut Context<Self>) {
375        let count = self.delegate.match_count();
376        if count > 0 {
377            self.set_selected_index(0, true, window, cx);
378            cx.notify();
379        }
380    }
381
382    fn select_last(&mut self, _: &menu::SelectLast, window: &mut Window, cx: &mut Context<Self>) {
383        let count = self.delegate.match_count();
384        if count > 0 {
385            self.set_selected_index(count - 1, true, window, cx);
386            cx.notify();
387        }
388    }
389
390    pub fn cycle_selection(&mut self, window: &mut Window, cx: &mut Context<Self>) {
391        let count = self.delegate.match_count();
392        let index = self.delegate.selected_index();
393        let new_index = if index + 1 == count { 0 } else { index + 1 };
394        self.set_selected_index(new_index, true, window, cx);
395        cx.notify();
396    }
397
398    pub fn cancel(&mut self, _: &menu::Cancel, window: &mut Window, cx: &mut Context<Self>) {
399        if self.delegate.should_dismiss() {
400            self.delegate.dismissed(window, cx);
401            cx.emit(DismissEvent);
402        }
403    }
404
405    fn confirm(&mut self, _: &menu::Confirm, window: &mut Window, cx: &mut Context<Self>) {
406        if self.pending_update_matches.is_some()
407            && !self.delegate.finalize_update_matches(
408                self.query(cx),
409                Duration::from_millis(16),
410                window,
411                cx,
412            )
413        {
414            self.confirm_on_update = Some(false)
415        } else {
416            self.pending_update_matches.take();
417            self.do_confirm(false, window, cx);
418        }
419    }
420
421    fn secondary_confirm(
422        &mut self,
423        _: &menu::SecondaryConfirm,
424        window: &mut Window,
425        cx: &mut Context<Self>,
426    ) {
427        if self.pending_update_matches.is_some()
428            && !self.delegate.finalize_update_matches(
429                self.query(cx),
430                Duration::from_millis(16),
431                window,
432                cx,
433            )
434        {
435            self.confirm_on_update = Some(true)
436        } else {
437            self.do_confirm(true, window, cx);
438        }
439    }
440
441    fn confirm_input(&mut self, input: &ConfirmInput, window: &mut Window, cx: &mut Context<Self>) {
442        self.delegate.confirm_input(input.secondary, window, cx);
443    }
444
445    fn confirm_completion(
446        &mut self,
447        _: &ConfirmCompletion,
448        window: &mut Window,
449        cx: &mut Context<Self>,
450    ) {
451        if let Some(new_query) = self.delegate.confirm_completion(self.query(cx), window, cx) {
452            self.set_query(new_query, window, cx);
453        } else {
454            cx.propagate()
455        }
456    }
457
458    fn handle_click(
459        &mut self,
460        ix: usize,
461        secondary: bool,
462        window: &mut Window,
463        cx: &mut Context<Self>,
464    ) {
465        cx.stop_propagation();
466        window.prevent_default();
467        self.set_selected_index(ix, false, window, cx);
468        self.do_confirm(secondary, window, cx)
469    }
470
471    fn do_confirm(&mut self, secondary: bool, window: &mut Window, cx: &mut Context<Self>) {
472        if let Some(update_query) = self.delegate.confirm_update_query(window, cx) {
473            self.set_query(update_query, window, cx);
474            self.delegate.set_selected_index(0, window, cx);
475        } else {
476            self.delegate.confirm(secondary, window, cx)
477        }
478    }
479
480    fn on_input_editor_event(
481        &mut self,
482        _: &Entity<Editor>,
483        event: &editor::EditorEvent,
484        window: &mut Window,
485        cx: &mut Context<Self>,
486    ) {
487        let Head::Editor(ref editor) = &self.head else {
488            panic!("unexpected call");
489        };
490        match event {
491            editor::EditorEvent::BufferEdited => {
492                let query = editor.read(cx).text(cx);
493                self.update_matches(query, window, cx);
494            }
495            editor::EditorEvent::Blurred => {
496                self.cancel(&menu::Cancel, window, cx);
497            }
498            _ => {}
499        }
500    }
501
502    fn on_empty_head_blur(&mut self, window: &mut Window, cx: &mut Context<Self>) {
503        let Head::Empty(_) = &self.head else {
504            panic!("unexpected call");
505        };
506        self.cancel(&menu::Cancel, window, cx);
507    }
508
509    pub fn refresh_placeholder(&mut self, window: &mut Window, cx: &mut App) {
510        match &self.head {
511            Head::Editor(editor) => {
512                let placeholder = self.delegate.placeholder_text(window, cx);
513                editor.update(cx, |editor, cx| {
514                    editor.set_placeholder_text(placeholder, cx);
515                    cx.notify();
516                });
517            }
518            Head::Empty(_) => {}
519        }
520    }
521
522    pub fn refresh(&mut self, window: &mut Window, cx: &mut Context<Self>) {
523        let query = self.query(cx);
524        self.update_matches(query, window, cx);
525    }
526
527    pub fn update_matches(&mut self, query: String, window: &mut Window, cx: &mut Context<Self>) {
528        let delegate_pending_update_matches = self.delegate.update_matches(query, window, cx);
529
530        self.matches_updated(window, cx);
531        // This struct ensures that we can synchronously drop the task returned by the
532        // delegate's `update_matches` method and the task that the picker is spawning.
533        // If we simply capture the delegate's task into the picker's task, when the picker's
534        // task gets synchronously dropped, the delegate's task would keep running until
535        // the picker's task has a chance of being scheduled, because dropping a task happens
536        // asynchronously.
537        self.pending_update_matches = Some(PendingUpdateMatches {
538            delegate_update_matches: Some(delegate_pending_update_matches),
539            _task: cx.spawn_in(window, |this, mut cx| async move {
540                let delegate_pending_update_matches = this.update(&mut cx, |this, _| {
541                    this.pending_update_matches
542                        .as_mut()
543                        .unwrap()
544                        .delegate_update_matches
545                        .take()
546                        .unwrap()
547                })?;
548                delegate_pending_update_matches.await;
549                this.update_in(&mut cx, |this, window, cx| {
550                    this.matches_updated(window, cx);
551                })
552            }),
553        });
554    }
555
556    fn matches_updated(&mut self, window: &mut Window, cx: &mut Context<Self>) {
557        if let ElementContainer::List(state) = &mut self.element_container {
558            state.reset(self.delegate.match_count());
559        }
560
561        let index = self.delegate.selected_index();
562        self.scroll_to_item_index(index);
563        self.pending_update_matches = None;
564        if let Some(secondary) = self.confirm_on_update.take() {
565            self.do_confirm(secondary, window, cx);
566        }
567        cx.notify();
568    }
569
570    pub fn query(&self, cx: &App) -> String {
571        match &self.head {
572            Head::Editor(editor) => editor.read(cx).text(cx),
573            Head::Empty(_) => "".to_string(),
574        }
575    }
576
577    pub fn set_query(&self, query: impl Into<Arc<str>>, window: &mut Window, cx: &mut App) {
578        if let Head::Editor(ref editor) = &self.head {
579            editor.update(cx, |editor, cx| {
580                editor.set_text(query, window, cx);
581                let editor_offset = editor.buffer().read(cx).len(cx);
582                editor.change_selections(Some(Autoscroll::Next), window, cx, |s| {
583                    s.select_ranges(Some(editor_offset..editor_offset))
584                });
585            });
586        }
587    }
588
589    fn scroll_to_item_index(&mut self, ix: usize) {
590        match &mut self.element_container {
591            ElementContainer::List(state) => state.scroll_to_reveal_item(ix),
592            ElementContainer::UniformList(scroll_handle) => {
593                scroll_handle.scroll_to_item(ix, ScrollStrategy::Top)
594            }
595        }
596    }
597
598    fn render_element(
599        &self,
600        window: &mut Window,
601        cx: &mut Context<Self>,
602        ix: usize,
603    ) -> impl IntoElement {
604        div()
605            .id(("item", ix))
606            .cursor_pointer()
607            .on_click(cx.listener(move |this, event: &ClickEvent, window, cx| {
608                this.handle_click(ix, event.modifiers().secondary(), window, cx)
609            }))
610            // As of this writing, GPUI intercepts `ctrl-[mouse-event]`s on macOS
611            // and produces right mouse button events. This matches platforms norms
612            // but means that UIs which depend on holding ctrl down (such as the tab
613            // switcher) can't be clicked on. Hence, this handler.
614            .on_mouse_up(
615                MouseButton::Right,
616                cx.listener(move |this, event: &MouseUpEvent, window, cx| {
617                    // We specifically want to use the platform key here, as
618                    // ctrl will already be held down for the tab switcher.
619                    this.handle_click(ix, event.modifiers.platform, window, cx)
620                }),
621            )
622            .children(self.delegate.render_match(
623                ix,
624                ix == self.delegate.selected_index(),
625                window,
626                cx,
627            ))
628            .when(
629                self.delegate.separators_after_indices().contains(&ix),
630                |picker| {
631                    picker
632                        .border_color(cx.theme().colors().border_variant)
633                        .border_b_1()
634                        .py(px(-1.0))
635                },
636            )
637    }
638
639    fn render_element_container(&self, cx: &mut Context<Self>) -> impl IntoElement {
640        let sizing_behavior = if self.max_height.is_some() {
641            ListSizingBehavior::Infer
642        } else {
643            ListSizingBehavior::Auto
644        };
645        match &self.element_container {
646            ElementContainer::UniformList(scroll_handle) => uniform_list(
647                cx.entity().clone(),
648                "candidates",
649                self.delegate.match_count(),
650                move |picker, visible_range, window, cx| {
651                    visible_range
652                        .map(|ix| picker.render_element(window, cx, ix))
653                        .collect()
654                },
655            )
656            .with_sizing_behavior(sizing_behavior)
657            .flex_grow()
658            .py_1()
659            .track_scroll(scroll_handle.clone())
660            .into_any_element(),
661            ElementContainer::List(state) => list(state.clone())
662                .with_sizing_behavior(sizing_behavior)
663                .flex_grow()
664                .py_2()
665                .into_any_element(),
666        }
667    }
668
669    #[cfg(any(test, feature = "test-support"))]
670    pub fn logical_scroll_top_index(&self) -> usize {
671        match &self.element_container {
672            ElementContainer::List(state) => state.logical_scroll_top().item_ix,
673            ElementContainer::UniformList(scroll_handle) => {
674                scroll_handle.logical_scroll_top_index()
675            }
676        }
677    }
678}
679
680impl<D: PickerDelegate> EventEmitter<DismissEvent> for Picker<D> {}
681impl<D: PickerDelegate> ModalView for Picker<D> {}
682
683impl<D: PickerDelegate> Render for Picker<D> {
684    fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
685        let editor_position = self.delegate.editor_position();
686
687        v_flex()
688            .key_context("Picker")
689            .size_full()
690            .when_some(self.width, |el, width| el.w(width))
691            .overflow_hidden()
692            // This is a bit of a hack to remove the modal styling when we're rendering the `Picker`
693            // as a part of a modal rather than the entire modal.
694            //
695            // We should revisit how the `Picker` is styled to make it more composable.
696            .when(self.is_modal, |this| this.elevation_3(cx))
697            .on_action(cx.listener(Self::select_next))
698            .on_action(cx.listener(Self::select_prev))
699            .on_action(cx.listener(Self::select_first))
700            .on_action(cx.listener(Self::select_last))
701            .on_action(cx.listener(Self::cancel))
702            .on_action(cx.listener(Self::confirm))
703            .on_action(cx.listener(Self::secondary_confirm))
704            .on_action(cx.listener(Self::confirm_completion))
705            .on_action(cx.listener(Self::confirm_input))
706            .children(match &self.head {
707                Head::Editor(editor) => {
708                    if editor_position == PickerEditorPosition::Start {
709                        Some(self.delegate.render_editor(&editor.clone(), window, cx))
710                    } else {
711                        None
712                    }
713                }
714                Head::Empty(empty_head) => Some(div().child(empty_head.clone())),
715            })
716            .when(self.delegate.match_count() > 0, |el| {
717                el.child(
718                    v_flex()
719                        .flex_grow()
720                        .when_some(self.max_height, |div, max_h| div.max_h(max_h))
721                        .overflow_hidden()
722                        .children(self.delegate.render_header(window, cx))
723                        .child(self.render_element_container(cx)),
724                )
725            })
726            .when(self.delegate.match_count() == 0, |el| {
727                el.child(
728                    v_flex().flex_grow().py_2().child(
729                        ListItem::new("empty_state")
730                            .inset(true)
731                            .spacing(ListItemSpacing::Sparse)
732                            .disabled(true)
733                            .child(
734                                Label::new(self.delegate.no_matches_text(window, cx))
735                                    .color(Color::Muted),
736                            ),
737                    ),
738                )
739            })
740            .children(self.delegate.render_footer(window, cx))
741            .children(match &self.head {
742                Head::Editor(editor) => {
743                    if editor_position == PickerEditorPosition::End {
744                        Some(self.delegate.render_editor(&editor.clone(), window, cx))
745                    } else {
746                        None
747                    }
748                }
749                Head::Empty(empty_head) => Some(div().child(empty_head.clone())),
750            })
751    }
752}