gpui-action

longbridge/gpui-component · updated Apr 8, 2026

$npx skills add https://github.com/longbridge/gpui-component --skill gpui-action
0 commentsdiscussion
summary

Actions provide declarative keyboard-driven UI interactions in GPUI.

skill.md

Overview

Actions provide declarative keyboard-driven UI interactions in GPUI.

Key Concepts:

  • Define actions with actions! macro or #[derive(Action)]
  • Bind keys with cx.bind_keys()
  • Handle with .on_action() on elements
  • Context-aware via key_context()

Quick Start

Simple Actions

use gpui::actions;

actions!(editor, [MoveUp, MoveDown, Save, Quit]);

const CONTEXT: &str = "Editor";

pub fn init(cx: &mut App) {
    cx.bind_keys([
        KeyBinding::new("up", MoveUp, Some(CONTEXT)),
        KeyBinding::new("down", MoveDown, Some(CONTEXT)),
        KeyBinding::new("cmd-s", Save, Some(CONTEXT)),
        KeyBinding::new("cmd-q", Quit, Some(CONTEXT)),
    ]);
}

impl Render for Editor {
    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
        div()
            .key_context(CONTEXT)
            .on_action(cx.listener(Self::move_up))
            .on_action(cx.listener(Self::move_down))
            .on_action(cx.listener(Self::save))
    }
}

impl Editor {
    fn move_up(&mut self, _: &MoveUp, cx: &mut Context<Self>) {
        // Handle move up
        cx.notify();
    }

    fn move_down(&mut self, _: &MoveDown, cx: &mut Context<Self>) {
        cx.notify();
    }

    fn save(&mut self, _: &Save, cx: &mut Context<Self>) {
        // Save logic
        cx.notify();
    }
}

Actions with Parameters

#[derive(Clone, PartialEq, Action, Deserialize)]
#[action(namespace = editor)]
pub struct InsertText {
    pub text: String,
}

#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
#[action(namespace = editor, no_json)]
pub struct Digit(pub u8);

cx.bind_keys([
    KeyBinding::new("0", Digit(0), Some(CONTEXT)),
    KeyBinding::new("1", Digit(1), Some(CONTEXT)),
    // ...
]);

impl Editor {
    fn on_digit(&mut self, action: &Digit, cx: &mut Context<Self>) {
        self.insert_digit(action.0, cx);
    }
}

Key Formats

// Modifiers
"cmd-s"         // Command (macOS) / Ctrl (Windows/Linux)
"ctrl-c"        // Control
"alt-f"         // Alt
"shift-tab"     // Shift
"cmd-ctrl-f"    // Multiple modifiers

// Keys
"a-z", "0-9"    // Letters and numbers
"f1-f12"        // Function keys
"up", "down", "left", "right"
"enter", "escape", "space", "tab"
"backspace", "delete"
"-", "=", "[", "]", etc.  // Special characters

Action Naming

Prefer verb-noun pattern:

actions!([
    OpenFile,      // ✅ Good
    CloseWindow,   // ✅ Good
    ToggleSidebar, // ✅ Good
    Save,          // ✅ Good (common exception)
]);

Context-Aware Bindings

const EDITOR_CONTEXT: &str = "Editor";
const MODAL_CONTEXT: &str = "Modal";

// Same key, different contexts
cx.bind_keys([
    KeyBinding::new("escape", CloseModal, Some(MODAL_CONTEXT)),
    KeyBinding::new("escape", ClearSelection, Some(EDITOR_CONTEXT)),
]);

// Set context on element
div()
    .key_context(EDITOR_CONTEXT)
    .child(editor_content)

Best Practices

✅ Use Contexts

// ✅ Good: Context-aware
div()
    .key_context("MyComponent")
    .on_action(cx.listener(Self::handle))

✅ Name Actions Clearly

// ✅ Good: Clear intent
actions!([
    SaveDocument,
    CloseTab,
    TogglePreview,
]);

✅ Handle with Listeners

// ✅ Good: Proper handler naming
impl MyComponent {
    fn on_action_save(&mut self, _: &Save, cx: &mut Context<Self>) {
        // Handle save
        cx.notify();
    }
}

div().on_action(cx.listener(Self::on_action_save))

Reference Documentation

  • Complete Guide: See reference.md
    • Action definition, keybinding, dispatch
    • Focus-based routing, best practices
    • Performance, accessibility

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.675 reviews
  • Zara Rahman· Dec 20, 2024

    I recommend gpui-action for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Li Bhatia· Dec 20, 2024

    Registry listing for gpui-action matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Camila Kim· Dec 16, 2024

    gpui-action reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Chaitanya Patil· Dec 12, 2024

    gpui-action reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Aisha Harris· Dec 12, 2024

    gpui-action fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • William Ghosh· Dec 8, 2024

    Solid pick for teams standardizing on skills: gpui-action is focused, and the summary matches what you get after install.

  • Aisha Flores· Dec 8, 2024

    Keeps context tight: gpui-action is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Zara Ramirez· Dec 4, 2024

    Registry listing for gpui-action matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Kofi Smith· Nov 27, 2024

    We added gpui-action from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Fatima Patel· Nov 23, 2024

    Useful defaults in gpui-action — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

showing 1-10 of 75

1 / 8