pub struct Keymap { /* private fields */ }Expand description
A set of key→command bindings for one platform.
Implementations§
Source§impl Keymap
impl Keymap
Sourcepub fn new(mac: bool, bindings: Vec<(&str, Command)>) -> Self
pub fn new(mac: bool, bindings: Vec<(&str, Command)>) -> Self
Build a keymap. mac selects whether Mod means Cmd/Meta (macOS) or
Ctrl. Binding strings use --separated modifiers, e.g.
"Mod-b", "Mod-Shift-z", "Enter".
Sourcepub fn handle(
&self,
state: &EditorState,
press: &KeyPress,
dispatch: Option<&mut Dispatch<'_>>,
) -> bool
pub fn handle( &self, state: &EditorState, press: &KeyPress, dispatch: Option<&mut Dispatch<'_>>, ) -> bool
Handle a key press. Returns whether a binding matched (and ran, if a dispatch was given and the command applied).
Lookup is two-pass: first the exact canonical form, then — if shift
was held and the key isn’t a lowercase ASCII letter — the same form
with shift stripped. That mirrors the browser convention where a
key like > or ? is always produced with Shift, so a binding
like "Mod->" shouldn’t have to spell out Shift.
Sourcepub fn add(&mut self, spec: &str, command: Command)
pub fn add(&mut self, spec: &str, command: Command)
Add or replace a binding by its Mod--using key spec (e.g.
"Mod-b"). Extensions use this to inject bindings on top of
base_keymap.
Sourcepub fn add_chained(&mut self, spec: &str, command: Command)
pub fn add_chained(&mut self, spec: &str, command: Command)
Add a binding, chaining it in front of any existing binding for
the same key rather than replacing it: the new command is tried
first and the previous one becomes its fallback. Because
well-behaved commands report false (and do nothing) when they
don’t apply, this lets independent extensions cooperate on a shared
key — e.g. Tab running cell-navigation inside a table and
list-indent inside a list, each a no-op in the other’s context.