gpui: Add keybinding macro for library-default key bindings - #60742
Closed
mikayla-maki wants to merge 3 commits into
Closed
gpui: Add keybinding macro for library-default key bindings#60742mikayla-maki wants to merge 3 commits into
mikayla-maki wants to merge 3 commits into
Conversation
Components can now declare an action and register a default key binding
for it in one step:
keybinding!("enter", Confirm);
keybinding!("escape", Cancel, "TextInput");
The action is registered under the crate's namespace (via the new
crate_namespace flag on the Action derive), and the binding is
registered at link time with inventory and added to every App's keymap
at creation, before any user bindings, so user keymaps shadow defaults
through declaration-order precedence.
Applications that own their entire keymap can opt out with
Application::without_default_key_bindings; Zed does. Individual
defaults can be masked by binding NoAction over them.
- The Action derive's existing namespace argument now accepts the literal token crate to use the compiling crate's name, replacing the separate crate_namespace flag. - Default key bindings load at the beginning of Application::run (and run_embedded), gated on a flag that without_default_key_bindings clears pre-run, so opting out truly skips loading. Test, headless, bench, and visual-test contexts load them at construction.
mikayla-maki
marked this pull request as draft
July 11, 2026 23:01
Contributor
|
To keep the PR queue cleaner, will close this PR for now, as this is a draft still with no changes for over 3 weeks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GPUI-native components need working keyboard behavior without requiring every application to assemble a keymap. This adds the registration half of that story:
keybinding!declares the action (likeactions!) and registers a default binding for it in one step. Actions are named under the registering crate's namespace via the existingnamespaceargument on theActionderive, which now acceptsnamespace = crateto use the compiling crate's name (readsCARGO_CRATE_NAMEat expansion).inventory, the same mechanism actions already use), so third-party component crates participate identically with zero init code, and defaults are genuinely pre-user.Application::run(andrun_embedded; test/headless/bench contexts load at construction), before any user bindings, so user keymaps shadow defaults via declaration-order precedence. This stays action-based rather than raw key dispatch, so user remapping, the command palette, and keymap introspection all keep working.Application::without_default_key_bindings()is a pre-run builder flag that skips loading entirely (Zed sets it, since it owns its whole keymap via JSON); individual defaults can be masked by bindingNoActionover them.KeyBinding::is_default()exposes provenance for keymap UIs.Part of the groundwork for a GPUI-native component library (with #60739 and #60740).
Release Notes: