command_palette.rs

 1use std::marker::PhantomData;
 2
 3use crate::prelude::*;
 4use crate::{example_editor_actions, OrderMethod, Palette};
 5
 6#[derive(Element)]
 7pub struct CommandPalette<V: 'static> {
 8    view_type: PhantomData<V>,
 9    scroll_state: ScrollState,
10}
11
12impl<V: 'static> CommandPalette<V> {
13    pub fn new(scroll_state: ScrollState) -> Self {
14        Self {
15            view_type: PhantomData,
16            scroll_state,
17        }
18    }
19
20    fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
21        div().child(
22            Palette::new(self.scroll_state.clone())
23                .items(example_editor_actions())
24                .placeholder("Execute a command...")
25                .empty_string("No items found.")
26                .default_order(OrderMethod::Ascending),
27        )
28    }
29}