Skip to main content

Module keys

Module keys 

Source
Expand description

Reading the keymap back, so a printed accelerator is the one that fires.

Every chord a surface shows — a menu row’s trailing ⌘N, a toolbar button’s tooltip — is a claim about the keymap, and a hand-typed string is a claim nothing checks. Bind cmd-b somewhere else and the button still says ⌘B. So the label is resolved from the binding instead of written beside it: shortcut asks gpui what is bound right now, and an action with nothing bound to it prints nothing rather than a chord that is no longer true.

Dispatch is untouched. Nothing here fires an action — a menu still runs what the app wires to it, and this only answers what the keyboard would have run.

§Replacing what a component binds

Every init in this crate is its bindings() bound, and that list is public. Three ways to change it, none of which is copying it out:

cx.bind_keys(input::bindings());                       // the defaults
cx.bind_keys([KeyBinding::new("ctrl-w", input::DeleteWordLeft, ctx)]);
cx.bind_keys([KeyBinding::new("cmd-z", NoAction, ctx)]);

A later binding wins the dispatch, gpui::NoAction takes a chord away, and an app that wants neither skips init and binds a filtered bindings(). Whichever it does, what is printed follows — that is what the rest of this module is for.

Functions§

format
Format a binding’s keystrokes the way the platform writes them.
shortcut
The chord bound to action for whatever holds focus right now, formatted for the platform.
shortcut_in
The chord bound to action in a named key context, whatever holds focus.