Skip to main content

Module palette

Module palette 

Source
Expand description

CommandPalette — a filtered command list over a input::TextField.

Stateful for the same reason the text field is: it owns a query, a filtered view of the items and an active row. It reports outcomes as gpui events rather than taking a callback, so the host decides what a selection means and the palette never knows about the app’s actions.

The state underneath is popover::Filter, shared with crate::combobox::Combobox and tested there.

ui::palette::init(cx);   // once, at startup (with input::init)
let palette = cx.new(|cx| CommandPalette::new(vec!["Open File".into()], cx));
cx.subscribe(&palette, |_, _, event, _| match event {
    PaletteEvent::Selected(index) => { /* run command `index` */ }
    PaletteEvent::Dismissed => { /* unmount */ }
})
.detach();

Re-exports§

pub use input::KEY_CONTEXT as FIELD_KEY_CONTEXT;

Structs§

CommandPalette
Confirm
Dismiss
SelectNext
SelectPrevious

Enums§

PaletteEvent
What the palette reports. Indices are into the ORIGINAL item list, never into the filtered view — a caller matching on a filtered index would run the wrong command the moment a query is typed.

Constants§

KEY_CONTEXT
The key context the palette claims. It wraps the field’s own context, so typing goes to the field while navigation keys fall through to here.

Functions§

bindings
The palette’s navigation keymap, as data, so an app can have it without having to take it — see crate::keys for layering over it or taking a chord away.
init
Install the bindings — bindings, bound. Call once, alongside crate::input::init.