GPUI Box GitHub

Components / controls

KeymapEditor view

Coordinates one recorder over caller-owned keymap rows; it never applies a binding.

A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).

use gpui_kit::controls::keymap_editor::KeymapEditor;

Reviewed in keymap-editor.

Construct
new(ident: impl Into<Ident>, window: &mut Window, cx: &mut Context<Self>) -> Self
Options

Chain onto the value.

commands(commands: impl IntoIterator<Item = KeymapCommand>) -> Self
query(query: impl Into<SharedString>) -> Self
Commands

Need a Context, so they need a view.

set_commands(commands: Vec<KeymapCommand>, cx: &mut Context<Self>)
set_query(query: impl Into<SharedString>, cx: &mut Context<Self>)
set_disabled(disabled: bool, cx: &mut Context<Self>)
Queries

Only answer; they change nothing.

active_command() -> Option<&SharedString>
is_disabled() -> bool
current_commands() -> &[KeymapCommand]
Reports

The variants of the event it emits. It never applies the change itself.

  • AddCaptured
  • Remove
  • Reset
  • RecordingCancelled
Example · keymap-editor
fn keymap_editor(window: &mut Window, cx: &mut App) -> AnyElement {
    if !cx.has_global::<SceneKeymapEditor>() {
        let editor = cx.new(|cx| {
            KeymapEditor::new("scene.keymap-editor", window, cx).commands([
                KeymapCommand::new("workspace.open", "Open workspace")
                    .context("Workspace")
                    .defaults(["cmd-o"])
                    .bindings([
                        KeymapBinding::new("user", "cmd-shift-o")
                            .conflict("Already opens recent workspaces")
                            .provenance("User keymap"),
                        KeymapBinding::new("workspace", "ctrl-o").provenance("Workspace keymap"),
                    ])
                    .searchable("Open a folder or project", ["folder", "project"]),
                KeymapCommand::new("terminal.toggle", "Toggle terminal")
                    .context("Terminal")
                    .defaults(["ctrl-`"])
                    .bindings([KeymapBinding::new("default", "ctrl-`")])
                    .searchable("Show the integrated terminal", ["panel", "console"]),
                KeymapCommand::new("policy.locked", "Managed shortcut")
                    .context("Workspace")
                    .defaults(["cmd-l"])
                    .bindings([KeymapBinding::new("managed", "cmd-l").provenance("Host policy")])
                    .refused("This binding is managed by the host."),
            ])
        });
        cx.set_global(SceneKeymapEditor(editor));
    }
    let editor = cx.global::<SceneKeymapEditor>().0.clone();
    let theme = cx.theme().clone();

    stack(&theme)
        .w(px(760.0))
        .child(editor)
        .child(caption(
            &theme,
            "Bindings remain caller-owned; add, remove, and reset are intents.",
        ))
        .into_any_element()
}

Source: crates/gpui-kit/src/controls/keymap_editor.rs