Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T04:43:35.651Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

head.rs

76 lines · 2.1 KB · rust
1use std::sync::Arc;
2
3use gpui::{App, Entity, FocusHandle, Focusable, prelude::*};
4use ui::prelude::*;
5use ui_input::{ErasedEditor, ErasedEditorEvent};
6
7/// The head of a [`Picker`](crate::Picker).
8pub(crate) enum Head {
9    /// Picker has an editor that allows the user to filter the list.
10    Editor(Arc<dyn ErasedEditor>),
11
12    /// Picker has no head, it's just a list of items.
13    Empty(Entity<EmptyHead>),
14}
15
16impl Head {
17    pub fn editor<V: 'static>(
18        placeholder_text: Arc<str>,
19        mut edit_handler: impl FnMut(&mut V, &ErasedEditorEvent, &mut Window, &mut Context<V>) + 'static,
20        window: &mut Window,
21        cx: &mut Context<V>,
22    ) -> Self {
23        let editor = (ui_input::ERASED_EDITOR_FACTORY.get().unwrap())(window, cx);
24
25        editor.set_placeholder_text(placeholder_text.as_ref(), window, cx);
26        let this = cx.weak_entity();
27        editor
28            .subscribe(
29                Box::new(move |event, window, cx| {
30                    this.update(cx, |this, cx| (edit_handler)(this, &event, window, cx))
31                        .ok();
32                }),
33                window,
34                cx,
35            )
36            .detach();
37        Self::Editor(editor)
38    }
39
40    pub fn empty<V: 'static>(
41        blur_handler: impl FnMut(&mut V, &mut Window, &mut Context<V>) + 'static,
42        window: &mut Window,
43        cx: &mut Context<V>,
44    ) -> Self {
45        let head = cx.new(EmptyHead::new);
46        cx.on_blur(&head.focus_handle(cx), window, blur_handler)
47            .detach();
48        Self::Empty(head)
49    }
50}
51
52/// An invisible element that can hold focus.
53pub(crate) struct EmptyHead {
54    focus_handle: FocusHandle,
55}
56
57impl EmptyHead {
58    fn new(cx: &mut Context<Self>) -> Self {
59        Self {
60            focus_handle: cx.focus_handle(),
61        }
62    }
63}
64
65impl Render for EmptyHead {
66    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
67        div().track_focus(&self.focus_handle(cx))
68    }
69}
70
71impl Focusable for EmptyHead {
72    fn focus_handle(&self, _: &App) -> FocusHandle {
73        self.focus_handle.clone()
74    }
75}
76
Served at tenant.openagents/omega Member data and write actions are omitted.